孙肖宁

javascript控制鼠标经过显示和隐藏二维码
描述:当鼠标经过的时候,显示二维码,鼠标移开的时候,二维码隐藏,并且二维码时钟位于所有内容最前面,并且处于同一位置...
扫描右侧二维码阅读全文
27
2018/03

javascript控制鼠标经过显示和隐藏二维码

描述:当鼠标经过的时候,显示二维码,鼠标移开的时候,二维码隐藏,并且二维码时钟位于所有内容最前面,并且处于同一位置。
注意:图片根据自己的项目来进行自定义。
实现代码如下:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>显示和隐藏二维码</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .content{
            width: 1200px;
            height: 1200px;
            margin: 0 auto;
            background: aquamarine;
        }
        .small{
            width: 50px;
            height: 50px;
            position: fixed;
            top: 200px;
            right: 10px;
        }
        .big{
            width: 152px;
            height: 149px;
            position: fixed;
            top: 200px;
            right: 60px;
            display: none;
            z-index: 5;
        }
        .show{
            display: block;
        }
        .hide{
            display: none;
        }
    </style>
</head>
<body>
<div class="content">
        <div class="small">
            <a href="#" class="aBig">
                <img src="images/smal1.jpg" />
            </a>
        </div>
        <div class="big">
            <img src="images/big.png" />
        </div>
    </div>
</body>
</html>
<script>
    /*获取相关元素和事件源*/
    var small = document.getElementsByClassName("aBig")[0];
    var big = document.getElementsByClassName("big")[0];
    /*绑定事件*/
    small.onmouseover = fn1;
    small.onmouseout = fn2;
    /*定义方法*/
    function  fn1() {
        big.className = "big show";
    }
    function fn2() {
        big.className = "big hide";
    }
</script>
Last modification:March 27th, 2018 at 08:49 pm
If you think my article is useful to you, please feel free to appreciate

Comment here is closed