Blink screen by clicking on menu before sliding to destination

Asked

Viewed 292 times

1

take a look at this link Fun Wake Park click on the menu and you will notice that before the sliding effect happens, the page goes to the destination and comes back quickly with a blink, what can this be? I’m using the jquery.easing, told me to use the ScrollTo of Tweenmax but I found it complicated I didn’t understand how it applies.

Can you help me with this ?

Code calling the plugin:

$(function() {
$('a').bind('click',function(event){
    var $anchor = $(this);

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

 });

});

  • 1

    The JS on the page is all minified... difficult to help. It seems to me a FOUC but the page is not loading... forehead event.preventDefault() to prevent the browser from scrolling and in the millisecond after that comes jQuery’s Animate.

  • Through what you flw went to search, and tested add a false Return; in function and apparently testing in place worked out. Thanks

  • And tested with event.preventDefault()?

  • I tested yes, I do not know if I did wrong but it ended up working, only the Return worked.

1 answer

0


I think the problem is you’re not stopping the event.

When you click an anchor the browser will open on a new page, or jump to the point of the page. If you use a url it goes to a new page, if you use #id he goes to a certain position where he finds this element within the same page.

Once this behavior is not stopped, the browser goes to that page site and at the same time starts a scroll. This shuffles and gives this effect.

If my theory is right (because I can’t test it on your website) I need to stop the event. And this is how you can do it:

$(function() {
    $('a').bind('click',function(event){
        event.preventDefault(); // ou return false no final desta função
        var $anchor = $(this);
        $('html, body').stop().animate({scrollTop:$($anchor.attr('href')).offset().top}, 2000,'easeInOutExpo');
    });
});
  • That’s exactly what I did following your line of reasoning was research, and tested the return:false; and it worked, already sub air pro project a look. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.