0

div が 5 つの div のうち 3 番目であり、div の上部に移動し、スライドされた div の下に他の div をプッシュする必要がある場合、ページの上部に div をスライドさせるにはどうすればよいですか?

私が見つけた最も近い結果はこれです: http://biostall.com/demos/swap-and-reorder-divs-smoothly-using-jquery/

それに関する唯一の問題は、すべてのdivの一番上にスライドさせたい別のdivと位置を交換していることです

4

1 に答える 1

0

デモ

html

Click on a box
<img />
<img />
<img />
<img />
<img />

js/jQ

var y = 100;
$('img').each(function () {
    $(this).css("top", y + "px");
    $(this).css("background-color", "rgb(0,90," + y + ")");
    y += 55;
});


$('img').click(function (e) {

    $(e.target).animate({
        top: "100"
    });

    $(e.target).siblings().each(function () {
        if ($(this).position().top < $(e.target).position().top) {
            $(this).animate({
                top: "+=55"
            });
        }
    });

});

CSS

img {
    height:50px;
    width:50px;
    position:absolute;
    left:20px;
    cursor:pointer;
}
于 2013-06-13T15:02:18.477 に答える