不支持悬停功能
Not support hover function?
鼠标功能无法支持
$("div.container1:has('#image')").hover(function() {
console.log("Success hover");
});
这是我的div类
<div class="container1">
<img src="img/1920/blue.jpg" id="imageId"/>
</div>
div类中用于点击操作的功能
$(document).ready(function() {
$(".container1").click(function(e) {
e.preventDefault();
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
var img = $('<button>');
img.css('top', y);
img.css('left', x);
img.css('position', 'absolute');
img.attr('type', 'button');
img.attr('id', 'image');
img.css('z-index', 1);
img.attr('class', 'btn btn-info btn-lg');
$(this).attr('data-toggle','modal');
$(this).attr('data-target','#myModal');
img.attr('data-toggle','modal');
img.attr('data-target','#myModal');
console.log("Mouse action Start");
img.appendTo('.container1');
/*$(this).removeClass('.container1');*/
console.log("Mouse action End");
$(this).removeClass('<button>');
});
});
另一种选择作品的方式,jsbin
$("div.container1 #imageId").hover(function() {
console.log("Success hover");
});
这是因为.hooper需要两个参数。鼠标进入时的回调和离开时的回调。
另外,您是在添加DOM元素,然后添加单击处理程序吗?如果是这样,那么您肯定需要使用.on()
。
.on()用于动态添加到DOM中的元素。您可能需要执行.on('mouseenter', [callback])
和.on('mouseleave', [callback])
而不是.hover()
。仅供参考。
相关文章:
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 悬停功能触发器
- OpenLayers在悬停时高亮显示功能,并在单击时选择
- 使用Jquery创建一个具有单击和悬停功能的菜单
- 如何通过悬停或点击谷歌电子表格中的单元格来运行自定义功能
- 美国地图插件,具有状态数据/悬停功能的新按钮
- JS“切换”或“悬停”功能
- 如何在保持鼠标悬停功能的同时居中跨过图像
- Jquery悬停功能显示和隐藏元素
- 在悬停功能中设置超时
- 不支持悬停功能
- 悬停几秒钟后启动功能
- 鼠标悬停功能获胜'不起作用
- 关于单击或悬停功能
- 为什么jquery是悬停的,在下拉菜单上滑动功能闪烁
- 使用 JavaScript 显示和隐藏导航栏进行滚动和悬停功能
- 具有悬停延迟的 OpenLayers 选择功能控件
- 如果悬停:动画完成后重新调用功能
- Jquery滑动悬停功能显示.stop错误(但仍然有效)
- 如何在功能悬停时获得指针光标,但前提是没有被弹出窗口覆盖