自己写了个小效果,但是不知道为什么一直不是很顺畅。老是闪。

hopperhuang hopperhuang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想要的效果是:鼠标指就出现一个遮挡层。
鼠标离开对象,遮挡层就消失。
我用了两种方法都是这样。鼠标一移动遮挡层就消失,然后又出现。这样闪啊闪啊。
是我的CODE有哪里不对吗?请大神来帮帮我,教教我怎么优化,谢谢。
下面是我的CODE

<!DOCTYPE>
<html>
<head>
<meta charset = "utf-8" />
<script src = "http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
<script>
//$().ready(function(){
//$(".div1").mouseover(function(){
//$(".div2").show();
//} )
/*$("img").mouseenter(function(event){
event.stopPropagation();
$(".div2").stop().css("display","inline");
} )
.mouseleave(function(event){
event.stopPropagation();
$(".div2").stop().css( "display", "none");
} )
} )
*/
$().ready(function(){
$(".div1").mouseenter(function(){
$(".div2").clearQueue();
$(".div2").addClass("modal");
} )
.mouseleave(function(){
$(".div2").clearQueue();
$(".div2").removeClass("modal");
} )
})
</script>
<style>
.div1 {
width:100px;
height:100px;
}
img {
width:100px;
}
.modal {
width:100px;
height:100px;
background-color:grey;
position:absolute;
left:8px;
top:0;
opacity:0.6;
}
</style>
</head>
<body>
<div class = "div1">
<div>
<img src = "6011443968.jpg">
</div>
</div>
<div class = "div2" >
</div>
</body>
</html>

...全文
评论 2
收藏 已收藏
分享
返回顶部
hopperhuang
JavaScript 87,983 成员 224,681 内容