最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery get the height from top - Stack Overflow

programmeradmin0浏览0评论

I need to get the height from top of the page to current scrollbar position and place it to my link:

<a class="poplight" rel="popup_name" href="#?w=here comes the value"></a>

How can I do this?

I need to get the height from top of the page to current scrollbar position and place it to my link:

<a class="poplight" rel="popup_name" href="#?w=here comes the value"></a>

How can I do this?

Share Improve this question edited Jun 18, 2012 at 15:41 Jay Sullivan 18.2k11 gold badges65 silver badges88 bronze badges asked Jun 18, 2012 at 15:35 Daniel KoczułaDaniel Koczuła 1,0343 gold badges16 silver badges31 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

Use the offset()

$('.poplight').offset().top

If you need to scroll to that position:

$('html, body').animate({
    scrollTop: $('.poplight').offset().top
}, 400);

If you need the distance from the top of the window to the current position based on scroll:

$(window).scrollTop()

Want to add that to the url:

$(".poplight").attr("href", "#" + $(window).scrollTop())
发布评论

评论列表(0)

  1. 暂无评论