Prevent page from scrolling to top

后端 未结 2 1621
花落未央
花落未央 2020-12-20 02:48

I have a little problem with jQuery Mobile and anchor link\'s by url.

When page is load, after jquery throw event\'s work fine, but then jquery execute code and move

相关标签:
2条回答
  • 2020-12-20 03:43

    The default behavior of jQuery Mobile when showing pages is to scroll to top upon showing a page. The value of scroll is always 0 and stored in $.mobile.defaultHomeScroll.

    You need to override this value on any page event but before page is totally shown and transition is done.

    if (location.hash == "#wopwop") { 
      $.mobile.defaultHomeScroll = $('#wopwop').offset().top; 
    }
    

    This will force scrolling to wopwop div's offset in page without scrolling to top and then back to that div.

    0 讨论(0)
  • 2020-12-20 03:47
    $(document).ready(function(){
        $('html, body').animate({ scrollTop: $("#wopwop").offset().top }, 7000);
    });
    
    0 讨论(0)
提交回复
热议问题