时间:2021-07-01 10:21:17 帮助过:5人阅读
<!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实现鼠标放到图片上产生遮罩效果的代码案例的详细内容,更多请关注Gxl网其它相关文章!