Javascript 不支持悬停功能?
无法支持鼠标功能Javascript 不支持悬停功能?,javascript,jquery,html,hover,Javascript,Jquery,Html,Hover,无法支持鼠标功能 $("div.container1:has('#image')").hover(function() { console.log("Success hover"); }); 这是我的课 <div class="container1"> <img src="img/1920/blue.jpg" id="imageId"/> </div> div类中用于单击操作的功能 $(document).ready(fu
$("div.container1:has('#image')").hover(function() {
console.log("Success hover");
});
这是我的课
<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>');
});
});
$(文档).ready(函数(){
$(“.container1”)。单击(函数(e){
e、 预防默认值();
var x=e.pageX-this.offsetLeft;
变量y=e.pageY-this.offsetTop;
var img=$('');
img.css(“顶部”,y);
img.css('left',x);
img.css(‘位置’、‘绝对’);
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');
log(“鼠标操作启动”);
附件('.container1');
/*$(this.removeClass('.container1')*/
log(“鼠标操作结束”);
$(此).removeClass(“”);
});
});
这是因为.hover需要两个参数。鼠标移动时的回调,以及鼠标离开时的回调
另外,您是在添加DOM元素,然后添加click处理程序吗?如果是这样,您肯定需要使用.on()
.on()用于动态添加到DOM中的元素。
您可能需要执行
.on('mouseenter',[callback])
和.on('mouseleave',[callback])
而不是.hover()
。仅供参考。选择作品的另一种方式
你们能说得更清楚些吗,你们面临的确切问题是什么?我有背景图片。我尝试热点类型。所以现在我有很多按钮和一个背景图像。我需要按钮悬停功能。我也尝试了,但无法响应
$("div.container1 #imageId").hover(function() {
console.log("Success hover");
});