admin管理员组文章数量:1356771
I have this javascript: In the javascript. You can click on the a element. I want the scrollTop in pixels of the a element. When i used console.log. See in my example. I get this:
[
Object
scrollTop: 649
__proto__: Object
]
But the problem is. How can i get the 649? I want to put the 649 in a variable.?
Javascript
$("a[href*='#']").click(function(e){
e.preventDefault();
var offset = $(document).find($(e.target).attr('href')).offset();
if(!offset)
var offset = $(document).find($(e.target).parent().attr('href')).offset();
var test = $({ scrollTop: offset.top });
console.log(test);
});
I have this javascript: In the javascript. You can click on the a element. I want the scrollTop in pixels of the a element. When i used console.log. See in my example. I get this:
[
Object
scrollTop: 649
__proto__: Object
]
But the problem is. How can i get the 649? I want to put the 649 in a variable.?
Javascript
$("a[href*='#']").click(function(e){
e.preventDefault();
var offset = $(document).find($(e.target).attr('href')).offset();
if(!offset)
var offset = $(document).find($(e.target).parent().attr('href')).offset();
var test = $({ scrollTop: offset.top });
console.log(test);
});
Share
Improve this question
asked Jan 13, 2012 at 7:31
Mike VierwindMike Vierwind
1,5204 gold badges24 silver badges44 bronze badges
2 Answers
Reset to default 4Just use offset.top
. You wrote code to wrap that in an object. That code is not needed.
In jquery will be like this
$('#yourElement').offset().top;
本文标签: javascriptGet the scrolltop of the elementStack Overflow
版权声明:本文标题:javascript - Get the scrolltop of the element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743994682a2572770.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论