亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - How to implement the distance between the inside of a DIV and the mouse in JS
大家講道理
大家講道理 2017-05-16 13:37:29
0
2
651

This is a problem that I can’t solve even if I tear my brain apart↓

Front-ends! As shown in the figure, how to obtain the coordinate distance from the leftmost side of p to the mouse position?

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

reply all(2)
Ty80
    body{
        margin:0;
        padding:0;
    }
    #p{
        width:200px;
        height:100px;
        border:1px solid #000;
        position:absolute;
    }
    //如果p有定位父級元素存在還需要減去offsetTop值
    $("#p").bind("click",function(ev){
        console.log(ev.clientX - $(this).offset().left);
    })
僅有的幸福
$("p").on("click",function(e){
    var disX = e.clientX - e.offsetX;    //disX就是當(dāng)前p最左側(cè)到鼠標(biāo)位置的坐標(biāo)距離
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template