简体   繁体   English

scrollTop()没有滚动到IE Windows 8手机上的正确位置

[英]scrollTop() is not scrolling to the correct place on IE windows 8 phone

It's working fine everywhere, although the browser returns the right height, it scrolls to the wrong position(different one each time) this only happens on IE W8 phone, here is the code: 尽管浏览器返回正确的高度,但它在任何地方都可以正常工作,但它滚动到错误的位置(每次都不同),这仅在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(); });

Any idea? 任何想法?

Although this is messy, but for some reason it worked. 虽然这很麻烦,但是由于某种原因它起作用了。 I had to call animate twice in order to scroll to the right place. 为了滚动到正确的位置,我不得不两次调用动画。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM