Firefox jquery scrollTo flicker bug

允我心安 提交于 2019-12-23 10:09:56

问题


I've seen quite a few threads here talking about flickering in Firefox, but none that quite describe the problem I'm having.

I've got a horizontal scrolling website, fixed position menus, and the jquery plugin .scrollTo handling next and previous buttons. This works great in Chrome and Safari (don't know about IE), but in Firefox there is a flicker every time you scroll right of left with the arrows in the upper right and corner.

See An Example Here

I've tried setting all the elements that have a fixed position to overflow:auto but that did nothing. I'm not super familiar with with JS or Jquery but I know enough to change things. Any help would be greatly appreciated!


回答1:


The problem is that you are not cancelling the default browser action in your click function. Change your code to this, and the flicker will go away:

$(function(){
    $(".next").click(function(e) {
        $.scrollTo( '+=1000px', 600 );
        e.preventDefault();
    });
    $(".prev").click(function(e) {
        $.scrollTo( '-=1000px', 600 );
        e.preventDefault();
    });
});

Firefox is trying to "scroll to the #" and animate at the same time.




回答2:


Right after my comment on page bookmarkability on Doug's post, the light in my head turned on! Hope you can adapt to your script, if you need bookmarkability

<a href="#gohere" class="mylink">Click</a>
...

$('.mylink').click(function(e) {
    e.preventDefault();
    var anchor = $(this).attr('href');
    $.scrollTo(anchor, 1000, {
        onAfter: function(){
          location.hash = anchor;
        }
    });   
});


来源:https://stackoverflow.com/questions/1904118/firefox-jquery-scrollto-flicker-bug

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