【问题标题】:scrollTop() is not scrolling to the correct place on IE windows 8 phonescrollTop() 没有滚动到 IE windows 8 手机上的正确位置
【发布时间】:2013-05-23 17:33:03
【问题描述】:

它在任何地方都可以正常工作,虽然浏览器返回正确的高度,但它滚动到错误的位置(每次都不一样)这只发生在 IE W8 手机上,这里是代码:

$("#navigation-wrapper a").click(function(e){
    $headerHeight = $("#header").height();
    var $anchor = $(this);
    $('html, body').stop().animate({scrollTop: $($anchor.attr('href')).offset().top - $headerHeight});
e.preventDefault(); });

有什么想法吗?

【问题讨论】:

  • 我也刚刚注意到这一点。对我来说,它也在弹跳,但它不应该弹跳,所以我假设它是一个 jQuery 错误。

标签: jquery internet-explorer mobile windows-mobile


【解决方案1】:

虽然这很混乱,但由于某种原因它起作用了。我不得不调用 animate 两次才能滚动到正确的位置。

$('html, body').stop()
  .animate({scrollTop: $($anchor.attr('href')).offset().top - $headerSize},function(){
      $('html, body').stop()
        .animate({scrollTop: $($anchor.attr('href')).offset().top - $headerSize});
    });

【讨论】:

    猜你喜欢
    • 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
    相关资源
    最近更新 更多