使DIV在悬停时显示在光标旁边
Make DIV show next to cursor on hover
我已经设置了我目前拥有的JSFiddle,基本功能工作,但div似乎只是显示它所在的位置,而不是通过光标。这在现场的网站结果在框显示没有地方附近的复选框,起初我认为这是一个问题的位置或z-索引,但现在我不这么认为。
好吧,我已经得到了这个工作在一个JS提琴,但由于某种原因,它不工作在网站上…它在菜单'Your Event'下
http://217.199.187.74/merlineventslondon.com/
任何帮助都会很棒- http://jsfiddle.net/ThisWebGuy/GYXE2/
JS
// Awards Dinner
$("input[type='checkbox'][value='awards-dinner']").mouseover(function(){
$(".awardsbox").show();
$(".awardsbox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='awards-dinner']").mouseout(function(){
$(".awardsbox").hide();
});
// Awards Dinner Dance
$("input[type='checkbox'][value='awards-dinner-dance']").mouseover(function(){
$(".awardsdinnerdancebox").show();
$(".awardsdinnerdancebox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='awards-dinner-dance']").mouseout(function(){
$(".awardsdinnerdancebox").hide();
});
// Cocktail Party
$("input[type='checkbox'][value='cocktail-party']").mouseover(function(){
$(".cocktailbox").show();
$(".cocktailbox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='cocktail-party']").mouseout(function(){
$(".cocktailbox").hide();
});
// Dinner
$("input[type='checkbox'][value='dinner']").mouseover(function(){
$(".dinnerbox").show();
$(".dinnerbox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='dinner']").mouseout(function(){
$(".dinnerbox").hide();
});
// Dinner and Dance
$("input[type='checkbox'][value='dinner-dance']").mouseover(function(){
$(".dinnerdancebox").show();
$(".dinnerdancebox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='dinner-dance']").mouseout(function(){
$(".dinnerdancebox").hide();
});
// Networking Event
$("input[type='checkbox'][value='networking-event']").mouseover(function(){
$(".networkingbox").show();
$(".networkingbox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='networking-event']").mouseout(function(){
$(".networkingbox").hide();
});
// Party
$("input[type='checkbox'][value='party']").mouseover(function(){
$(".partybox").show();
$(".partybox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 15) + "px"
});
});
$("input[type='checkbox'][value='party']").mouseout(function(){
$(".partybox").hide();
});
HTML <label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="awards-dinner">Awards Dinner</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="awards-dinner-dance">Awards Dinner Dance</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="barbat-mitzvah">Bar/Bat Mitzvah</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="cocktail-party">Cocktail Party</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="dinner">Dinner</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="dinner-dance">Dinner Dance</label> <br>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="networking-event">Networking Event</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="party">Party</label>
<label><input type="checkbox" id="tchkb-1" name="taxo[1][term][]" value="vip-experience">VIP Experience</label>
<div class="awardsbox">
<p>Perfect for a formal dinner with an awards presentation. AV equipment and a team of technicians are included to ensure your event goes smoothly as well as a three course meal, unlimited wine, beer and soft drinks, staffing and furniture.</p>
</div>
<div class="awardsdinnerdancebox">
<p>Perfect for awards dinner celebrations or charity events. AV equipment and a team of technicians are included to ensure your event goes smoothly as well as a three course meal, unlimited wine, beer and soft drinks, staffing and furniture. Not to forget a DJ and Disco to ensure your guests dance the night away.</p>
</div>
<div class="dinnerdancebox">
<p>This style of event is more formal and ideal for events where you may need to entertain guests or clients with a formal drinks reception, dinner and a great party afterwards. A three course meal and unlimited wine, beer and soft drinks are included as well as AV, staffing and furniture.</p>
</div>
<div class="dinnerbox">
<p>This style of event is more formal and ideal for events where you may need to entertain clients without the full party or disco atmosphere. A three course meal and unlimited wine, beer and soft drinks are included as well as AV, staffing and furniture.</p>
</div>
<div class="partybox">
<p>Perfect for both corporate or private celebrations, parties include a DJ & Disco as well as a bowl food menu and unlimited wine, beer and soft drinks. AV, staffing and furniture are also included.</p>
</div>
<div class="networkingbox">
<p>A classic three hour networking event ideal for client parties where talking business is key. Canapés, unlimited wine, beer and soft drinks as well as staffing, AV and furniture are all included in our quotes.</p>
</div>
<div class="cocktailbox">
<p>A cocktail party is a classic three hour networking event ideal for client parties where talking business is key. Canapés, unlimited wine, beer and soft drinks as well as staffing, AV and furniture are all included in our quotes.</p>
</div>
CSS .awardsbox, .awardsdinnerdancebox, .dinnerdancebox, .dinnerbox, .partybox, .networkingbox, .cocktailbox{
display: none;
padding: 7px;
background-color: red;
width: 300px;
position:absolute;
z-index: 999;
}
函数中缺少'e'
.mouseover(function(e)
…
.mouseout(function(e){
…
如果你为事件添加参数'e'就可以了
获取当前鼠标位置并使用如下的x-y坐标
$("input[type='checkbox'][value='awards-dinner']").mouseover(function(e){
$(".awardsbox").show();
$(".awardsbox").css({
top: (e.pageY + 50) + "px",
left: (e.pageX + 50) + "px"
});
});
获取function(e)
参数中的事件为"e"
选中第一个复选框
编辑:对不起,我添加了代码来再次获得坐标。已经更新了代码并修改
http://jsfiddle.net/GYXE2/24/查看此提琴
太多的jquery代码,只是清理一些代码,这可能会减少文件大小。这就是jquery的作用。$(".showPopUp").mouseover(function(e){
$("."+this.id).show();
$("."+this.id).css({
top: e.pageY,
left: e.pageX
});
}).mouseout(function(){
$("."+this.id).hide();
});
这里有几件事需要注意,首先,当传递.css作为对象时,总是用引号括住键。
但是你在这里需要做的基本事情,在你的代码中,首先是在函数中传递事件,也就是…function(e),这样无论你接下来做什么,它都是可用的。
然后,您应该通过console.log(e)查看e的哪些属性可用。
通过这样做,您将看到(至少在FF中)坐标被标记为clientX和cliententy,因此您应该调用e.f clientX &e.clientY坐标。
我已经用你描述的第一个例子更新了你的jsfiddle,如果需要的话,看看并要求澄清。
$("input[type='checkbox'][value='awards-dinner']").mouseover(function(e){
console.log(e.clientX);
$(".awardsbox").show();
$(".awardsbox").css({
'top': e.clientY + "px",
'left': e.clientX + "px"
});
});
相关文章:
- 图像阵列预加载时显示沙漏光标
- 同时在两个文本框上显示光标
- fullcalendar赢得't让我调整事件大小(光标不显示,我做错了)
- Don'在IE中调用find next时,不要高亮显示Codemirror中的光标
- 如何在网页加载asp.net上显示文本框中第二个字母的光标位置
- javascript在foucs()后显示光标
- 我可以在HTML5画布中创建图形形状对象吗?以及当用户将鼠标悬停在形状上时如何将光标显示为指针
- 谷歌可视化时间线显示鼠标光标的时间
- 在 Twitter 引导程序中自动显示工具提示,而无需放置光标
- 显示进程(或等待)光标,而 jQuery 不起作用
- 实时显示所有当前访问者光标
- 如何在 SVG 上的鼠标光标旁边显示工具提示,尽管网站上有非 SVG 元素
- 键入.js脚本在iPhone6中不起作用,如果任何单词将在该行完成,在这种情况下,另一个单词不键入,仅显示光标
- 如何创建一个上下文菜单,该菜单仅在单击容器时显示在光标位置上
- 显示 404 找不到“蛞蝓”模板,当发布返回空光标 - 流星 - 铁路由器
- 在拖动时显示光标
- 切换光标以显示我可以放置元素的位置
- 使用 Javascript 同时显示 2 个光标
- IE9 内容可编辑中显示错误的光标
- 保存文本中光标高亮显示的位置