当类应用于其他5个div时,如何在mouseover上仅淡化1个div?
$("div.test").mouseenter(function() { $("div.innerDiv").fadeIn("slow"); }).mouseleave(function() { $("div.innerDiv").fadeOut("slow"); }); 1 2 3 4
所以现在这样做的原因是,如果我将鼠标hover在任何一个div上,那么所有这些都将会淡入。我只想把我hover的div淡入而不是全部。 我认为有一种方法可以在不改变div结构的情况下改变jQuery,但我不知道如何。
干得好。
$("div.test").mouseenter(function() { $('div.innerDiv',this).fadeIn("slow"); }).mouseleave(function() { $('div.innerDiv',this).fadeOut("slow"); });
$("div.test") .mouseenter(function() { $(this).find("div.innerDiv").fadeIn("slow"); }).mouseleave(function() { $(this).find("div.innerDiv").fadeOut("slow"); });
使用this
而不是字符串作为选择器
检查一下
$(".test").mouseenter(function() { $(this).fadeOut("slow"); }).mouseleave(function() { $(this).fadeIn("slow"); });
顺便说一句,我认为你想先fadeOut
,而不是fadeIn