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 badges1 Answer
Reset to default 20Use 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())