js实现图片产生遮罩效果 js实现鼠标移动到图片产生遮罩效果

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

js实现图片产生遮罩效果 js实现鼠标移动到图片产生遮罩效果

数星星的咚咚咚   2021-03-29 我要评论
想了解js实现鼠标移动到图片产生遮罩效果的相关内容吗,数星星的咚咚咚在本文为您仔细讲解js实现图片产生遮罩效果的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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>
  <div class="pic">
    <!-- <div id="mask"></div> -->
  </div>
</body>
<script>
  var pic=document.getElementsByClassName("pic")[0];
  var d=document.createElement("div");
  pic.onmouseenter=function(){
    // var d=document.createElement("div");
    d.id="mask";
    pic.appendChild(d);
  };
  pic.onmouseleave=function(){
    this.removeChild(d);
  }; 
</script>
</html>

效果图:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们