jquery获取某组件距离边框的距离

Posted 1998xujinren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery获取某组件距离边框的距离相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>jquery获取组件距离边界的距离</title>

<script src="../jquery.js"></script> 
 
</head>
    <body>
        <div id="div01" style="width:200px;height:200px; position:absolute; left:400px; top:100px; background-color:blue"></div>
    </body>
    
    
<script>
    var left1 = $("#div01").offset().left;
    var top1 = $("#div01").offset().top;
    
    console.info("left :" + left1);
    console.info("top :" + top1);
</script>
</html>    

效果:

技术图片

 

以上是关于jquery获取某组件距离边框的距离的主要内容,如果未能解决你的问题,请参考以下文章