gpt4 book ai didi

javascript - 查找div相对于窗口的左侧位置

转载 作者:太空宇宙 更新时间:2023-11-04 06:37:21 25 4
gpt4 key购买 nike

我想找到 div 相对于窗口的左侧位置。

Sample Page

我是这样做的

 var diff = ($('.content-wrapper').outerWidth(true) - $('.content-wrapper').outerWidth()) ;

这工作正常,但我想看看是否有更好的方法来做到这一点?

如有任何建议或帮助,我们将不胜感激。

提前致谢

最佳答案

使用getBoundingClientRect .

var left = document.querySelector('div').getBoundingClientRect().left;

关于javascript - 查找div相对于窗口的左侧位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54103584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com