(“限制历史记录状态更改以防止浏览器挂起。”
$(window).on("scroll", checkPosition);
/*
Scroll To Anchor Function
*/
$('a[href^="#"]').on('click', function(e) {
e.preventDefault();
var speed = 800;
var target = this.hash;
var $target = $(target);
if(position != target){
//Scroll to
$('html, body').animate({
'scrollTop': $target.offset().top
}, speed, 'swing', function() {
//Callback onced finished animating
});
} else {
wiggleElement($(".circle"));
}
});
/*
Update Location Hash
*/
function checkPosition() {
var scrolled = $(window).scrollTop();
$("section").each(function(){
var section_pos = $(this).offset().top - 100;
var section_height = $(this).height();
if (section_pos <= scrolled && section_pos + section_height > scrolled) {
position = '#' + $(this).attr('id');
if(history.replaceState) {
history.replaceState(null, null, position);
}
else {
location.hash = position;
}
$('.circle').removeClass("current");
if (!is_open) {
$(position + '_circle').addClass("current");
}
}
})
}
答案 0 :(得分:0)
所以我不知道节流是什么,这是我的方式的错误。
我已经限制了checkPosition函数,并且一切正常。
本·阿尔曼(Ben Alman)提供: http://benalman.com/projects/jquery-throttle-debounce-plugin/