【问题标题】:Stop animation on last element在最后一个元素上停止动画
【发布时间】:2010-12-27 08:55:05
【问题描述】:

我有一个滑动面板,在最后一个元素上我希望动画停止,我尝试使用 .is(':last') 并且它不会停止。这是我的代码。加载表单时,当前 var 设置为第一个元素。它向左动画并在您单击下一个按钮时继续动画我只想在最后一个元素上停止它

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>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    而不是:last,只需检查是否有.next() 兄弟姐妹,如下所示:

    jQuery('.wikiform .navigation input[name^=Next]').click(function () {
      if (current.next().length == 0) return;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 2016-07-11
      相关资源
      最近更新 更多