Paul
Paul

Reputation: 6176

function ScrollTop only works in one way

i'm stuck on a problem, i would like to use the same function to go up inside a window, with ScrollTop, but the "0" or "-=10" does not work. Do you understand why? If i put an alert, it recognizes the class "monter", but it never goes up to "0" or "-=10". Here is my code :

            function scroll_descendre(){
              var scrolling;
              $('.descendre, .monter').bind({
                    mousedown: function(){
                        var zone = $(this).prev();
                        scrolling = true; //this is here : 
                        if ($(this).attr('class')=='descendre') startScrolling(zone, '+=20');
                        else if($(this).attr('class')=='monter') startScrolling(zone, '0');
                    },
                    mouseup: function(){
                        scrolling = false;
                    },
                    click: function(e){
                        e.preventDefault();
                    }
                });

                function startScrolling(obj, param){
                if (!scrolling) {
                    obj.stop();
                } else {
                    obj.animate({"scrollTop": param}, "fast", function(){
                    if (scrolling) { startScrolling(obj, param); }
                    });
                }
            }
            }

Thanks for your help

Upvotes: 0

Views: 194

Answers (1)

DarthJDG
DarthJDG

Reputation: 16591

Have a look at the following line:

var zone = $(this).prev();

It might not be selecting the right element to animate. It's hard to tell without your HTML markup, but you have to change it to a different selector.

As your .monter element might be before the scrolling container, try changing it to:

var zone = $(this).next();

Upvotes: 1

Related Questions