Stop animation on last element

Posted by littleMan on Stack Overflow See other posts from Stack Overflow or by littleMan
Published on 2010-12-26T23:45:29Z Indexed on 2010/12/26 23:54 UTC
Read the original article Hit count: 198

Filed under:
|

I have a sliding panel and on the last element I want the animation to stop i've tried using the .is(':last') and it doesn't stop. here is my code. the current var is set to the first element when the form loads. It animates to the left and keeps animating when you click the next button i just want to stop it on the last element

jQuery('.wikiform .navigation input[name^=Next]').click(function () {
    if (current.is(':last')) return;
        jQuery('.wikiform .wizard').animate({ marginLeft: '-=' + current.width() + "px" }, 750);
        current = current.next();});

<div id="formView1" class="wikiform">
    <div class="wizard">

        <div id="view1" class="view">
            <div class="form">
                Content 1
            </div>        
        </div>
        <div id="view2" class="view">
            <div class="form">
                Content 2
            </div>
        </div>

    </div>
    <div class="navigation">
        <input type="button" name="Back" value=" Back " />
        <input type="button" name="Next " class="Next" value=" Next " />
        <input type="button" name="Cancel" value="Cancel" />
    </div>   
</div>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery