因为专注,所以专业
2005 - 2020

CSS中的pointer-events属性实现点穿效果

时间:2020-02-06 03:58:48    作者:八叔模板堂

CSS的pointer-events属性

代码实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test css pointer-events</title>
    <style>
        body{
            background: #eeeeee;
        }
        main{
            width: 880px;
            height: 500px;
            margin: 100px auto;
            position: relative;
            background: #FFFFFF;
            display: table;
        }
        .top{
            width: 100px;
            height: 100px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform:translate(-50%,-50%);
            display: table-cell;
            vertical-align: center;
            color: #FFFFFF;
            line-height: 100px;
            background: purple;
            pointer-events: none;
            cursor: pointer;
        }

        .under{
            width: 100px;
            height: 100px;
            position: absolute;
            top: 50%;
            left: 50%;

            text-align:center;
            line-height: 100px;
            color: #FFFFFF;
            border-radius:50%;
            background: orangered;
            cursor: zoom-in;
        }
    </style>
</head>
<body>
    <main>

        <div class="under">
            Under U
        </div>

        <div class="top">
            I am top div
        </div>

    </main>
</body>
<script type="text/javascript">
    let main = document.querySelector("main");
    let log = function (content) {
        let p = document.createElement("p");
        p.innerHTML = content;
        main.appendChild(p);
    };
    let t =document.querySelector(".top");
    t.addEventListener("click",function () {
            log("clicked the top!")
    },true);//捕获阶段
    let under =document.querySelector(".under");
    under.addEventListener("click",function () {
        log("clicked the under!!!")
    },true)//捕获阶段
</script>
</html>

运行结果

参考连接:http://www.hangge.com/blog/cache/detail_1859.html
来源:https://blog.csdn.net/csu_passer/article/details/81431999
赞(0
免费拨打  111-1111-1111
免费拨打  111-1111-1111免费拨打 111-1111-1111
微信二维码
手机二维码
返回顶部
返回顶部返回顶部