【问题标题】:Localscroll / ScrollTo not working on iPadLocalscroll / ScrollTo 在 iPad 上不起作用
【发布时间】:2013-12-06 13:05:52
【问题描述】:

我在使用 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();

【问题讨论】:

    标签: jquery ios ipad navigation scrollto


    【解决方案1】:

    设法通过这里找到修复: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);
    })();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多