achu
achu

Reputation: 797

how to block the scrollTo animation on click

How to prevent the scrollTo animation in on click event,

jQuery.scrollTo.window().queue([]).stop();

This code is not working for me

Upvotes: 0

Views: 53

Answers (1)

Marcel Wasilewski
Marcel Wasilewski

Reputation: 2679

I did something for you in jQuery.

with my first function i trigger the scrolling top animation. In the second one i check if the user clicked anywhere on the page (except the scroll to top button) and stopped the animation.

$(document).on("click", ".scroll", function(){
    $("html, body").animate({ scrollTop: 0 }, 5000);
    return false;
});

$(document).on("click", function(e) {
    var page = $("html, body");
    if (e.target !== $(".scroll")) {
       page.on("click", function(){
           page.stop();
       });  
    }
    return false;
});

Here i did a fiddle: https://jsfiddle.net/we99f20n/2/

Upvotes: 1

Related Questions