美文网首页
client距离

client距离

作者: daisx | 来源:发表于2017-04-27 20:13 被阅读0次

//当事件触发时,鼠标点击距离游览器坐标轴的距离,根据点击的位置不同可以得到不同的X和Y值
offsetleft:指当前元素到最近定位父级的距离,如果没有定位存在,会默认指向body
除了offsetleft,分别还有offsettop,offsetwidth,offsetheight,

<script>
    window.onload = function () {
        var box1=document.getElementById("box1");
        var box2=document.getElementById("box2");
        box2.onclick= function (event) {
            event=event||document.event;
            console.log(event);
            var x=event.clientX
            console.log(x);
            var  y=event.clientY
            console.log(y);
           var z=box2.offsetLeft;
            console.log(z);
        }

    }
</script>

相关文章

网友评论

      本文标题:client距离

      本文链接:https://www.haomeiwen.com/subject/zjunzttx.html