我已阅读关于此问题的其他问题和答案,但它们不适用于我,也许我错过了某些内容,或者我的示例稍有不同,我不知道。无论如何,我有一个文本和链接里面的div,我想创建一个新的div当用户悬停在这第一个div。问题是,当我结束第一个div时,第二个连续淡入淡出,即使我没有用鼠标离开第一个div。徘徊在div上的重复动画
下面是HTML代码:
<div id="content">
<h1>Portfolio</h1>
<div id="web">
<p>Web apps</p>
<a href="#">
First link
</a>
</div>
<div id="commentweb">
<p>The text that I want to show</p>
</div>
</div>
,这是jQuery的:
$(document).ready(function() {
$("#web").click(function(){
window.location=$(this).find("a").attr("href");
return false;
});
$("#commentweb").hide();
$("#web").hover(
function() {
$(this).children("a").children("img").attr("src","2.png");
$(this).css("background-color","#ecf5fb");
$(this).css('cursor', 'pointer');
$(this).css('border','1px solid #378ac4');
$(this).children("p").css("opacity","1.0");
$('#commentweb').stop(true, true).fadeIn();
},
function() {
$(this).children("a").children("img").attr("src","1.png");
$(this).children("p").css("opacity","0.5");
$(this).css("background-color","#e8e3e3");
$(this).css('border','1px solid grey');
$('#commentweb').stop(true, true).fadeOut();
}
);
});
我应该怎么做才能在动画褪色我在#web和淡入淡出时开始当我离开那个div时没有闪烁(即不断fadeIn和fadeOut)?
我已经添加了一个小提示向您展示问题:http://jsfiddle.net/mMB3F/ 它基本上发生在我悬停在文本上时。
哎。你在*那里得到了很多'$(this)'。为什么不'var $ self = $(this)'然后使用'$ self'?并使用'$ self.css({cursor:'pointer',border:'...',...})'。 –
@JaredFarrish - 或者只是将所有这些方法链接到一个选择器表达式? – adeneo
谢谢你们,我会链接css命令。 – user1301428