[英]Mouseenter and Mouseleave function in jquery
我有div框。 我想要当用户将鼠标悬停在它上或鼠标进入时,下一个div应该显示,当用户将鼠标移出可见的div时应该淡出。 我的功能无法正常工作。
<head>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function (){
$('.box').bind({
mouseenter: function (){
$(this).next().fadeIn('fast')
},
mouseout: function (){
$(this).next().fadeOut('fast')
}
})
})
</script>
<style>
body { margin:0}
.box { height:300px; width:300px; background:#F00}
.boxcaption { width:300px; height:300px; background:#00F; position:absolute; left:0; top:0; display:none}
</style>
</head>
<body>
<div class="wrap">
<div class="box"></div>
<div class="boxcaption"></div>
</div>
</body>
第二个元素在第一个元素之上。 因此,当您进行鼠标输入然后将其淡入时,会立即看到鼠标移出,这就是它逐渐消失的原因。 将第二个元素下移300像素,您会看到它起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.