本文实例为大家分享了js实现鼠标移动到图片产生遮罩效果的具体代码,供大家参考,具体内容如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>mask</title>
<style>
.pic{
width:300px;
height:250px;
background:url(icon/product1.jpg) no-repeat;
margin:40px auto;
}
#mask{
width:300px;
height:250px;
background-color: gray;
margin:40px auto;
opacity: 0.5;
z-index: 1000;
}
</style>
</head>
<body>
<p class="pic">
<!-- <p id="mask"></p> -->
</p>
</body>
<script>
var pic=document.getElementsByClassName("pic")[0];
var d=document.createElement("p");
pic.onmouseenter=function(){
// var d=document.createElement("p");
d.id="mask";
pic.appendChild(d);
};
pic.onmouseleave=function(){
this.removeChild(d);
};
</script>
</html>效果图:

以上就是JS实现鼠标放到图片上产生遮罩效果的代码案例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号