js實現鼠標移動到圖片產生遮罩效果
來源:懂視網
責編:小OO
時間:2020-11-27 22:27:31
js實現鼠標移動到圖片產生遮罩效果
本文實例為大家分享了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;opacity: 0.5。
導讀本文實例為大家分享了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;opacity: 0.5。
本文實例為大家分享了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>
效果圖:

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
js實現鼠標移動到圖片產生遮罩效果
本文實例為大家分享了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;opacity: 0.5。