【发布时间】:2014-04-29 10:54:57
【问题描述】:
我在一个页面上有一组元素,其中包含 id。
客户端希望能够有一个滚动,每次滚动到它时都会将 id 附加到 url 的末尾。
所以这是标记:
HTML:
<section class="body-large scrolled" id="drop-in-membership">
</section>
<section class="body-large scrolled" id="hotdesk-membership">
</section>
<section class="body-large scrolled" id="resident-membership">
</section>
<section class="body-large scrolled" id="studios">
</section>
JS:
$(window).scroll(function() {
var winTop = $(this).scrollTop();
var $scrolledDivs = $('.scrolled');
$.each($scrolledDivs, function(item) {
if( $(item).offset().top == winTop ) {
//console.log( this.attr('id') );
window.location.href + scrolledDivs.attr('id');
}
});
});
似乎没有任何效果。
谁能指点我正确的方向?
【问题讨论】:
-
您不会更改位置。试试
window.location.href += '/#' + scrolledDivs.attr('id')
标签: javascript jquery html scroll frontend