我遇到了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();
答案 0 :(得分:0)
通过此处管理以找到修复程序: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);
})();