我在localscroll方面遇到了问题-我有一个固定的页眉元素,它出现在顶部大约100个像素之后。当用户点击导航项目时,它会滚动到正确的位置,但当我尝试点击另一个菜单项目时,除非我稍微移动页面,否则它不会移动。
这种情况只发生在iPad上——它在桌面浏览器中运行良好。
有人有什么想法吗?
var sections = $('section,footer'),
links = $('nav a');
$(window).scroll(function() {
var currentPosition = $(this).scrollTop();
links.removeClass('selected');
sections.each(function() {
var top = $(this).offset().top - 100,
bottom = top + $(this).height();
if (currentPosition >= top && currentPosition <= bottom) {
$('a[href="#' + this.id + '"]').addClass('selected');
}
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
links.removeClass('selected');
$('.last a').addClass('selected');
}
});
});
$.localScroll();
设法通过此处找到修复程序:https://gist.github.com/mckamey/1e661854044177a95064
(function(){
var THROTTLE = 100,//ms
_timer = 0,
_dom = document.documentElement,
_width = _dom.style.width,
reset = function(){
// reset size, unfortunately forces another reflow
_dom.style.width = _width;
},
forceReflow = function(){
if (_timer) {
clearTimeout(_timer);
_timer = 0;
}
_width = _dom.style.width;
// force a reflow by increasing size 1px
_dom.style.width = (_dom.offsetWidth+1)+'px';
setTimeout(reset, 0);
},
onscroll = function() {
if (_timer) {
clearTimeout(_timer);
}
_timer = setTimeout(forceReflow, THROTTLE);
};
window.addEventListener('scroll', onscroll, false);
})();