简体   繁体   中英

JQuery autoscroll to bottom (but disable on mousescrolling)

I load my content per $.get and "follow" the new appended data per javascript-auto-scrolling. Now I want to disable autoscrolling if the user "scrolls manually", but the following scroll-to-bottom function also triggers the Jquery .scroll()-function - so it disables itsef.

if(self.testelem.hasClass("active")){
    $(document).scrollTop($(document).height());
}

How can I receive a mouse-wheel event or prevent scrollTop to trigger the .scroll()-function? I also tried to set a Timeout to block while scrollTop is working, but this isn't a great solution and has a few drawbacks.

Any suggestions?

EDIT : My current code:

I use the button #stb (scroll to bottom) and the class .active to to turn it off/on.

$.get("url", function(data){
    //do something          
    if(self.testelem.hasClass("active")){
        $(document).scrollTop($(document).height());
    }
}); 

$(document).scroll(function(){
    jQuery('html,body').queue([]).stop();  //try this
    //$("#stb").parent().removeClass("active");
});

ps: Yes, I know. There are a few quite similar questions. I read them, but they differ in important points.

To stop a scrollTo event on user-interruption mid-scroll try this:

$(document).scroll(function(){
    jQuery('html,body').queue([]).stop();  //try this
    //jQuery.scrollTo.window().queue([]).stop(); //failing that try this
});

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