Stop animation on last element
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>
Instead of :last
, just check if there is a .next()
sibling, like this:
jQuery('.wikiform .navigation input[name^=Next]').click(function () {
if (current.next().length == 0) return;
精彩评论