简体   繁体   中英

jQuery smooth scroll doesn't work on iPad and iPhone

I used a jquery smooth scroll effect, nothing fancy..just jQuery...and it doesn't seem to work iPad or iPhone or any other tablets..the url is here: http://teothemes.com/wp/viewpoint/

and this is the code I used for jquery smooth scroll:

jQuery(document).ready(function() {
jQuery("a[href*=#]").on('click', function() {
  if(parseInt(jQuery(this.hash).offset().top) !== parseInt(jQuery(window).scrollTop()))
    jQuery('html,body').animate({scrollTop:jQuery(this.hash).offset().top}, 1500);
});

});

If there's anyone that has any idea, it's highly appreciated.

您是否尝试过CSS属性-webkit-overflow-scrolling:touch ;?

I've read this is an iOS 6.1 issue, and it doesn't appear to be fixed in the earliest version of iOS 7. Don't really have a solid uncomplicated solution, so as a workaround, I'm using Gentle Anchors when iPhones and iPods are detected, and will update this post if I find I need it for other devices.

    $('html, body').stop().animate({
        'scrollTop': $target.offset().top }, 1000);
    if( /iPhone|iPod/i.test(navigator.userAgent) ) {
        Gentle_Anchors.Setup(target);
        //for iPhone & iPod 
    }

Unfortunately I'm seeing some stuttering unless I tell the page to set the viewport equal to the iPhone's portrait width in the <head> if one of these devices has been detected.

 $(document).ready(function() { $('.nav-wrapper ul li a').click(function(e) { $('html,body').animate({ scrollTop: jQuery(this.hash).offset().top-134}, 500); }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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