Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要获取从页面顶部到当前滚动条位置的高度并将其放置到我的链接中:
<a class="poplight" rel="popup_name" href="#?w=here comes the value"></a>
我怎样才能做到这一点?
使用偏移量()
$('.poplight').offset().top
如果您需要滚动到该位置:
$('html, body').animate({ scrollTop: $('.poplight').offset().top }, 400);
如果您需要基于滚动从窗口顶部到当前位置的距离:
$(window).scrollTop()
想要将其添加到 url:
$(".poplight").attr("href", "#" + $(window).scrollTop())