jquery,怎么解决hover事件有子标签造成闪动和执行onmouseout事件

iMouseWu 2013-10-02 08:23:27
<ul class="menu">
<li style="width:29px">
<a href="">
<img src="QQ1.png" class="icon" style="bottom: 0px; display: inline; opacity: 1;">
<img src="QQ.png" class="hover-icon" style="bottom: 150px; display: none; opacity: 1;">
</a>
</li><ul>

$(".menu li").hover(function(){
$(this).find(".icon").stop(true,true).animate({'bottom':"-150px"},"fast");
$(this).find(".icon").css('display',"none");
$(this).find(".hover-icon").stop(true,true).animate({'bottom':"0px"},"fast");
$(this).find(".hover-icon").css('display',"inline");

},function(){
$(this).find(".hover-icon").stop(true,true).animate({'bottom':"150px"},"fast");
$(this).find(".hover-icon").css('display',"none");
$(this).find(".icon").stop(true,true).css('display',"inline");
$(this).find(".icon").animate({'bottom':"0"},"fast");

}
);

希望点击这个图片,另外一个图片就会来替换,然后当鼠标移走了以后,又回复到原来的图片!
现在是当鼠标移动到这个Li上时候,会点击到<img》子元素,就会出现闪动,并且只是执行ommouseout事件,不能达到原来的效果!
有没有人能解释下这是为什么?
1.为什么会造成闪动
2.为什么会不断的执行onmouseout事件,而不执行ommouseover事件
3.有什么解决办法?
跪求高人解决!
...全文
197 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
iMouseWu 2013-10-03
  • 打赏
  • 举报
回复
引用 1 楼 u011461314 的回复:
看了半天,原来是 <a> 搞了个重新加载页面。 用这效果不累死才怪。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.a1 {
	width:300px;
	height:300px;
	border:1px solid #111;
}

.a2,.a3 {
	width:100px;
	height:100px;
	background-color:#a11;
}
.a3 {
	background-color:#9e1;
	display:none;
}

</style>
</head>
<body>
<div id='waitover' class='a1'>
<a href=''>
<span class='a2'>XXXX</span>
<span id='show' class='a3'>OOOO</span>
</a>
</div>
<script>
document.getElementById("waitover").onmouseover = function(){
	document.getElementById('show').style.display = 'inline';
}
</script>

</body>
</html>
请问。能否说的具体点?
zhjdg 2013-10-02
  • 打赏
  • 举报
回复
看了半天,原来是 <a> 搞了个重新加载页面。 用这效果不累死才怪。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.a1 {
	width:300px;
	height:300px;
	border:1px solid #111;
}

.a2,.a3 {
	width:100px;
	height:100px;
	background-color:#a11;
}
.a3 {
	background-color:#9e1;
	display:none;
}

</style>
</head>
<body>
<div id='waitover' class='a1'>
<a href=''>
<span class='a2'>XXXX</span>
<span id='show' class='a3'>OOOO</span>
</a>
</div>
<script>
document.getElementById("waitover").onmouseover = function(){
	document.getElementById('show').style.display = 'inline';
}
</script>

</body>
</html>

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧