iPad Flicker on auto scroll using JQuery and Scrollto plugin

此生再无相见时 提交于 2019-11-28 15:59:46
wsbrs

If you need vertical scroll only, you could use {'axis':'y'} as settings to scrollTo method.

$.scrollTo(*selector*, *time*, {'axis':'y'});

Have you tried this:

$('a[href=#target]').
    click(function(){
        var target = $('a[name=target]');
        if (target.length)
        {
            var top = target.offset().top;
            $('html,body').animate({scrollTop: top}, 1000);
            return false;
        }
    });

If you're just scrolling the page vertically you can replace the entire jQuery scrollTo plugin with this simple line:

$('html,body').animate({scrollTop: $("#scrollingTo").offset().top}, 1000, 'easeOutCubic');

Personally I do something like this

$('html,body').animate({scrollTop: $("#step-1").offset().top-15}, 1000, 'easeOutCubic',function(){
  //do stuff
});

I found that if I try to do other js work while it's scrolling it makes the browser crunch and the animation isn't smooth. But if you use the callback it'll scroll first, then do what you need.

I put a -15 at the end of .top because I wanted to show the top edge of the div I was scrolling do, simply for aesthetic purposes. 1000 is the duration in milliseconds of the animation.

Credit goes to the poster, animate, for the tip off.

Defining {'axis':'y'} has made it right! It helped me with slideUp/Down flickering.

I'm not sure if this applies to jquery animations. But the following seems to affect CSS animations.

http://css-infos.net/property/-webkit-backface-visibility

Syntax

-webkit-backface-visibility: visibility;

Parameters

visibility Determines whether or not the back face of a transformed element is visible. The default value is visible.

edit

Try applying it to every element and see what happens.

*{
 -webkit-backface-visibility: visible;
}

and try

*{
-webkit-backface-visibility: hidden;
}

It's just a guess really...

I will also confirm Tund Do's method works flawlessly. If you need a "left/right" variation of the same thing (as I did) here it is:

$('.pg6').click(function(){
    var target = $('#page6');
    if (target.length)
    {
        var left = target.offset().left;
        $('html,body').animate({scrollLeft: left}, 1000);
        return false;
    }
});

I would guess you could combine the two, grab the top position and chain the animates for a "left/right/up/down" animation also.

I had the same problem.

The problem is the ScrollTo plugin. Instead of using scrollto.js just use .animate with scrollTop. No more flickering in ipad/iphone.

Here it is with no flickering http://www.sneakermatic.com

You should include {axis: 'y'} in your options object. Also be sure that you have not enabled interrupt option. You can test this with {interrupt: false}.

You need to add e.preventDefault(); to each .click() call. This prevents the browser's default action, which is to stay in the same place. Hope this helps!
i.e.

$("#quicksand li, .client-list li").click(function (e) {
  e.preventDefault();
  ...
});

I'm having the same flickering on iPhone -- even with the preventDefault and return false options of canceling the default click event. It appears that on the device it tries to go back to the top of the page before scrolling. If you have both a scrollTop and scrollLeft animation going on it really gets buggy. It's jQuery's issue.. I've seen a scrolling method with mootools that doesn't have this issue. See this page: http://melissahie.com/

Thanks nicole for giving the example with mootools. It really seems to be a jQuery issue when trying to do a animation on BOTH scrollTop and scrollLeft.

With mootools:

var scroll = new Fx.Scroll(window, {duration: 1000, wait: false, transition: Fx.Transitions.quadInOut});
scroll.start(y, x);

it works flawlessly on iOS5!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!