JQUERY:简单获取div的偏移量
我想获取 div 的偏移量,但是当我尝试访问该 div 时,我说 [Object object]... 或未定义或 0.0;因为我认为我的方法是错误的:-(
这是页面:
我已经尝试过使用此代码:
var p = $(".product_72ivnj");
var offset = p.offset();
var final =( "left: " + offset.left + ", top: " + offset.top );
alert(final);
或者这样:
var p = $("#product_72ivnj");
var offset = p.offset();
var final =( "left: " + offset.left + ", top: " + offset.top );
alert(final);
但是赢了不起作用:-(
有人可以帮助我吗?
提前致谢。
亲切的问候。
卢卡。
i would like get the offsets of a div,but when i try to access to that div says me [Object object]... or undefined or 0.0;because i think that my method is wrong :-(
This is the code of the page:
And i have already tried with this code:
var p = $(".product_72ivnj");
var offset = p.offset();
var final =( "left: " + offset.left + ", top: " + offset.top );
alert(final);
Or this:
var p = $("#product_72ivnj");
var offset = p.offset();
var final =( "left: " + offset.left + ", top: " + offset.top );
alert(final);
But won't work :-(
Anyone can help me please?
Thanks in advance.
Kind regards.
Luca.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过等待页面加载?
不太确定语法,您应该检查 jQuery 文档。
Have you tried to wait for the page to be loaded ?
Not so sure about the syntax you should check it on jQuery documentation.