移动端点透事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <!--理想视口:meta:vp    content : width=device-width :宽度等于设备宽度
    user-scalable : 禁止用户缩放-->
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        html{
            font-size: 100px;
            /*方便计算;*/
        }
        .box{
            width:2.5rem;
            height:2.5rem;
            background: red;
            float:left;
        }
    </style>
    <script>
        (function () {
            function computedFont() {
                let winW = document.documentElement.clientWidth;
                document.documentElement.style.fontSize = winW/750*100+"px";
            }
            computedFont();
            // window 的resize事件是当前窗口大小发生改变时,会触发的事件函数;
            window.addEventListener("resize",computedFont)
        })();
    </script>
</head>
<body>
<div class="box"></div>
<script src="fastclick.js"></script>
<script>
    // 事件
    //1. querySelector : 获取一个;如果有多个,只获取第一个;
    //2. 不存在DOM映射;
    // 解决移动端300ms的延迟;
    window.addEventListener("load",function () {
        FastClick.attach(document.body);
    })
    let  box = document.querySelector(".box");
    box.onclick = function () {
        console.log(1);
    }
    // onclick : 点击; 在移动端点击事件onclick存在300ms的延迟;在移动端如果连续两次点击的时间不超过300ms,那么认为是双击事件;
   /* box.ondblclick = function(){
        console.log(3);
    }*/
    // 移动端不存在鼠标的事件;
    // 移动端提供了触摸事件: ontouchstart  ontouchmove  ontouchend
    box.ontouchstart = function () {
        console.log(100);
    }
    box.ontouchend = function () {
        console.log(300);
    }
    /*var  div = document.createElement("div");
    div.className = "box";
    document.body.appendChild(div);*/
</script>
</body>
</html>
复制代码

转载于:https://juejin.im/post/5c7f479b51882547021c5b27

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值