我需要移动按钮左右,然后再次使用jquery左右

I need to move Button left-right and then again left-right using jquery

本文关键字:左右 jquery 然后 移动 按钮      更新时间:2023-09-26

我能够移动按钮一次左右。但是我需要移动它2次,即左右移动和左右移动。

代码如下:

$(document).ready(function () {
    sayNoVisual(100);
});
function sayNoVisual(px) {
    $('.stepback').animate({
        'marginLeft': px
    }, function () {
        $('.stepback').animate({
            'marginLeft': 1
        });
    });
}

  <asp:Button ID="Button1" class="stepback"  runat="server" Text="Button" />
  • animate回调可以递归函数
  • 要增加值,应该使用"+=" + value

:

$(document).ready(function () {
    sayNoVisual(100, 2);
});
function sayNoVisual(px, r) {
    $('.stepback').animate({
        'marginLeft': "+=" + px
    }, function() {
        if(--r > 0) sayNoVisual(px, r);
    });
}

jsFiddle