在元素中使用mouseover和mouseout会使悬停持续闪烁
Using mouseover and mouseout in a element makes a hover blinking continuously
我使用动态ID在JSP页面上动态呈现两个元素。在鼠标悬停在每个元素上时,我呈现一个div
,在鼠标悬停时,我生成相同的display
值none
。问题是,当我将鼠标悬停在div
上时,div
一直在闪烁。我该如何解决这个问题?
示例代码:
<table>
<tr>
<td>
<div onmouseover="showblock(hoverdivid)" onmouseout="hideblock(hoverdivid)">india</div>
<div class="hoverdiv" id="dynamicallygenerated">
<li>a list of checkboxes with state names of the country hovered will be inserted using ajax</li>
</div>
</td>
<td>
<div onmouseover="" onmouseout="">america</div>
<div class="hoverdiv" id="dynamicallygenerated">
<li>a list of checkboxes with state names of the country hovered will be inserted using ajax</li>
</div>
</td>
</tr>
</table>
<script>
var showblock;
var hideblock;
$(document).ready(function (e) {
showblock = function (id) {
$("#" + id).show();
}
hideblock = function (id) {
$("#" + id).hide();
}
});
</script>
扩展我的问题
我提到过使用ajax在悬停中插入复选框,在同一个悬停中,我有一个添加按钮,它将我在悬停中选中的值添加到表外的其他div中。我有两个国家/地区,所以两个悬停都有他们的引用,所以当我选中并点击添加要显示的两个悬停的值时,应该单独显示,建议我解决上述要求的方法
之所以会发生这种情况,是因为当显示hoverdiv
时,您的鼠标在其上,从而触发mouseleave
事件,因此hoverdiv
消失,然后您的鼠标再次在第一个div
上,因此触发mouseenter
事件,从而再次出现hoverdiv
。。。。等等。这会导致闪烁
我最好的建议是嵌套hoverdiv:(你必须稍微调整一下css)
<table>
<tr>
<td>
<div onmouseover="" onmouseout="">
india
<div class="hoverdiv"></div>
</div>
</td>
<td>
<div onmouseover="" onmouseout="">
america
<div class="hoverdiv"></div>
</div>
</td>
</tr>
</table>
当hoverdiv
在另一个div
内时,当您悬停在hoverdiv
上时,mouseleave
将不会被触发
工作演示http://jsfiddle.net/cse_tushar/FKacT/1
HTML
<table border="1">
<tr>
<td>
<div class="div">india</div>
<div class="hoverdiv" id="dynamicallygenerated">
<li>a list of checkboxes with state names of the country hovered will be inserted using ajax</li>
</div>
</td>
<td>
<div class="div">america</div>
<div class="hoverdiv" id="dynamicallygenerated">
<li>a list of checkboxes with state names of the country hovered will be inserted using ajax</li>
</div>
</td>
</tr>
</table>
css
td{
vertical-align: top;
}
js
$(document).ready(function () {
$('.div').hover(function () {
x = $(this).css('width');
$(this).parent().find('.hoverdiv').show();
$(this).css('width', $(this).parent('td').width());
}, function () {
$(this).css('width', x);
$(this).parent().find('.hoverdiv').hide();
});
});
相关文章:
- 音频控件在mouseover上显示,在mouseout上淡出
- 当鼠标悬停在文本中的单词上时显示警报
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 手风琴可点击并悬停
- 悬停功能触发器
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- css(或jQuery)悬停时淡入淡出
- jquery快速悬停问题
- 如何在悬停时流畅地更改单词
- jQuery:当屏幕大小改变时,如何更改默认图像和悬停图像
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- Flexslider导航按钮在悬停时不可见,带有橙色框
- 使用Javascript,如何显示<tr>在另一<tr>悬停时,隐藏第二个<tr>
- jQuery mouseout动画仅在第二次悬停后启动
- 鼠标悬停&单个锚点标记中的mouseout事件
- 在元素中使用mouseover和mouseout会使悬停持续闪烁
- Mouseout函数正在被调用,而我'm仍然悬停在我的mouseover对象
- jQuery 2级悬停导航和mouseovers/mouseout