English 中文(简体)
j Query .each() - How to iterate over items and animate each of them separate causes ripple effect
原标题:jQuery .each() - how to iterate over items and animate each of them separately causing ripple effect

我有一页,有100个箱子被打上顶顶,打上了间歇。 我想用一些 j笑 an来模拟这种 te,使其回旋并产生连锁反应。

我第一次尝试这样做:

$("#teetering-tester").click(function () {
    $("#box-stack div").each(function (id) {
        $(this).animate({  margin-right : "+=3px" }, 300 + id, function () {
            $(this).animate({  margin-right : "-=3px" }, 300 + id);
        });
    });
    return false;
});

但是,这使得整个方面走向正确,进而走向正确。

我希望产生连锁反应。 因此,我试图以定时的方式打开新的天线:

$("#doTeeter").click(function () {
    $("#output").append("<li>Starting</li>");
    $("#box-stack div").each(function (id) {
        setTimeout($(this).animate({  margin-right : "+=3px" }, 300 + id, function () {
            $(this).animate({  margin-right : "-=3px" }, 300 + id);
        }), 700, function () {
            $("#output").append("<li>I m done</li>");
        });
    });
    return false;
});

整条主食一成不变。

我随后尝试:

$("#doTeeter").click(function () {
    $("#box-stack div").each(function (id) {
        setTimeout(teeterStack(id), 700);
    });
    return false;
});

... 

function teeterStack(id) {
    $("#box-stack div").eq(id)
        .animate({  margin-right : "+=3px" }, 500 + id, function () {
            $(this).animate({  margin-right : "-=3px" }, 300 + id);
        });
    });
}

但是,他们仍然走到一起。

How can I make a ripple effect across my 100 boxes?

任何帮助都将受到赞赏。

Thanks, Scott

Update

奥赫先生,我刚刚注意到,我试图增加一些变异性,使估计时间成为300米的功能,加上该项目的id。

Update 2

我只是试图这样做,这是一件事。

function teeterStack(id) {
    $("#box-stack div").eq(id)
        .animate({  margin-right : "+=3px" }, getTime(id), function () {
            $(this).animate({  margin-right : "-=3px" }, getTime(id));
        });
}
function getTime(id) {
    var min = 300, max = 2000, step = (max-min)/100;
    return (step*id) + min;
}

但是,我没有知道拖延,所以我会让那枪。

最佳回答

The trick is to delay the start of effect based on the elements index. Here s an untested poke at it. NOTE: using your first example.

$("#teetering-tester").click(function () {
    $("#box-stack div").each(function (id) {

        var stallFor = 300 * parseInt(id); // 300 is the gap between delays, tweek it based on visual preference

        $(this).delay(stallFor).animate({  margin-right : "+=3px" }, function () {
            $(this).animate({  margin-right : "-=3px" });
        });
    });
    return false;
});

Suggestion

页: 1 它混淆了变量的含义。

问题回答

我认为,你有定时的正确想法,但问题是,你在时间上重新使用同样的价值。 提供随机(或半随机)价值,说明设定时间功能的第二个论点,以取得你想要的效果。 假设这些编号是顺序编号,我就建议如下内容:<编码>(teeterStack(id),700+(id*100);。





相关问题
images sliding continuously with <table> and jQuery

I m trying to write a little test page that circulates images through a window (see image). I have colored boxes inside a table (gray border), with each box being a element. <table id="boxes" ...

WPF 3d rotation animations

I have a few 3d rectangles on my screen that I want to pivot around the Y axis. I want to press down with the mouse, and rotate the 3d object to a max rotation, but when the user moves their mouse, ...

Disable Windows 7 touch animation in WPF

In Windows 7 when you touch the screen there is a short animation that occurs at the touch point. In my WPF app I want to display my own touch points, without showing the one supplied by Windows. ...

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Direct 2D gnuplot PNG animation?

Can anyone please confirm that yes/no Gnuplot 4.5 (on CVS) can output 2D animated PNG files? I have numerous datasets but one line that I d like to show iteratively in 3 different places in my graph. ...

Visual State Manager VS Animations in WPF

There is a lot of talk about the simplicity of Visual States and the transitions between them in WPF/Silverlight. I have the need to generate animations dynamically at runtime, to animate the ...

Create a ImageIcon that is the mirror of another one

I ll like to know if there is a way to create a ImageIcon that is the mirror of another ImageIcon. Searching on Google, I found how to do it by using many AWT libraries. Is there a way to do it with ...

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...

热门标签