Ahhhhhhhhhhhhhdfgbv Ahhhhhhhhhhhhhdfgbv - 7 months ago 47
jQuery Question

Stop .animate() when it reaches last div

So I have a web app where each panel is 480x300 (-20px for status bar) and two navigation buttons to scroll left or right.

Now everything works great, except when you continue scrolling past the max panels displayed, it keeps going.

I was wondering if it is possible to stop the Jquery .animate() after it reaches the last panel.


Answer Source

Hiya another demo http://jsfiddle.net/qpHSw/ or http://jsfiddle.net/yEsDQ/ or http://jsfiddle.net/yEsDQ/show

this sample dynamically counts your li in ul and adjust the animate according.


   var cur = 1;
var max = $(".scroll-content ul").children("li").length;


    if (cur+1 > max) return;

        marginLeft: "-=500px",
    }, 1000);


    if (cur-1 < 1) return;
        marginLeft: "+=500px",
    }, 1000);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download