如何处理在UL/LI项中添加闭合链接
How to handle adding a close link within an UL/LI item
我有一些代码,像这样:
<ul id="ulPersonal">
<li class="break eTime">
<p>Manage your time card.</p>
<div id="dEtime">
some content
</div>
</li>
</ul>
div只在你放置在li
项上时出现,在jquery中:
$('#dEtime').hide(); //initially hide the div...
//when the user hovers show the div
$(".eTime").hover(function () {
$('#dEtime').fadeIn('slow');
});
基本上页面显示了li项,我把它放在上面,div就显示出来了。现在我尝试了一下,当你"取消悬停"的时候,div就会消失,但是用户体验并不友好……太多的闪烁。
所以我决定添加一个闭合的超链接…但是如果我将它添加到li项中并单击它,div会重新出现,因为我仍然"悬停"在li内。如何处理这个问题,以便允许用户关闭div?
我有很多单独的ul
项目这样做,所以我不想在ul之后添加关闭链接,显然我不能在li之外添加href
标签,因为这是完全错误的。
尝试使用。mouseenter()而不是。hover(),因为您只向.hover()
传递一个回调,它将为鼠标进入和离开条件调用
$('#dEtime').hide(); //initially hide the div...
$('#closeIt').hide(); //initially hide the div...
//when the user hovers show the div
$(".eTime").mouseenter(function () {
$('#dEtime').fadeIn('slow');
$('#closeIt').show(); //initially hide the div...
});
$("#closeIt").click( function(){
$('#dEtime').hide(); //initially hide the div...
$('#closeIt').hide();
});
演示:小提琴
相关文章:
- 为li元素添加标题
- 如何更改dynamicaly的主题添加了li项jquery mobile
- 无法在 DIV 中添加 LI 项
- 动画化并同时向 li 添加类
- 单击按钮时,我如何将li的id添加为1
- 页面加载后,在li remove上添加类
- Javascript为li添加了span
- Javascript 使用 array 将 li 添加到 ul
- 如何将现有 ul 的所有 li 添加到另一个 ul 的底部,基于他们的 css 类
- 将 li 添加到 ul 并查找是否存在
- 按下轮播中的按钮时自动向每个 li 添加类
- 将 li 添加到 ul
- 将所选li添加到现有ul中
- 在页面加载后向li添加类
- 如果内容是某个字符串,则向li添加类
- AngularJS:为li添加活动效果和悬停效果
- 向LI添加占位符attr
- 当单击里面的标记时,向li添加类
- 如何将带有多个类的新li添加到UL
- 向父类LI添加类,其中A =当前文档