JQuery滑动/向下循环?
我错在哪里? 只希望在鼠标离开该区域时.ex向上滑动。。但它似乎在循环,然后向上滑动JQuery滑动/向下循环?,jquery,loops,html,slidedown,slideup,Jquery,Loops,Html,Slidedown,Slideup,我错在哪里? 只希望在鼠标离开该区域时.ex向上滑动。。但它似乎在循环,然后向上滑动 $("div.case").mouseover(function () { var id = $(this).attr("id"); $(this).css("opacity", "1").css("filter", "alpha(opacity=100)"); $(".ex"+id).slideDown(500); }); $("div.case").mouseout(function () { var
$("div.case").mouseover(function () {
var id = $(this).attr("id");
$(this).css("opacity", "1").css("filter", "alpha(opacity=100)");
$(".ex"+id).slideDown(500);
});
$("div.case").mouseout(function () {
var id = $(this).attr("id");
$(this).css("opacity", "0.4").css("filter", "alpha(opacity=40)");
$(".ex"+id).slideUp(500);
});
有人知道可能是什么问题吗?尝试使用
mouseenter
和mouseleave
如果在具有绑定事件的元素中从每个子元素移动到另一个子元素,则也会触发事件mouseover
和mouseout
您还可以使用
鼠标悬停
,它是鼠标指针
和鼠标悬停
的别名。这可能是执行此功能的更好方法:
$('.case').hover(function(){
var id = $(this).attr('id');
$(this).css('opacity':'1','filter':'alpha(opacity=100)');
$('.ex'+id).slideDown(500);
},
function(){
var id = $(this).attr('id');
$(this).css('opacity':'0.4','filter':'alpha(opacity=40)');
$('.ex'+id).slideUp(500);
});
悬停方法使用两个函数。第一个是初始悬停函数,第二个是悬停退出回调函数。我猜的.ex
元素是以这种方式生成的<代码>0.ex0.ex1.ex2。如果是这样的话,你的功能应该可以发挥作用。如果.ex
元素位于.case
中,并且有多个.case
可以使用此选择器:
$('.ex',this)
如果您有此元素的列表,则可以使用取消id的方法并使用:eq()
索引选择器:
$('.ex:eq('+id+')')
基本上,
div.case
元素将在ex
div向下滚动=>后变得更高,如果您的鼠标靠近该区域,您仍然将div.case
$("div.case img").mouseover(function () {
....
}
$("div.case img").mouseout(function () {
....
}