将div滑动到div的顶部



如果div是5个div中的第3个div,它应该放在div的顶部,并将其他div推到滑动到顶部的div下面,我该如何将div滑动到页面顶部呢?

我找到的最接近的结果是:http://biostall.com/demos/swap-and-reorder-divs-smoothly-using-jquery/

唯一的问题是,它正在与另一个div交换位置,我希望它滑动到所有div的顶部

演示

Click on a box
<img />
<img />
<img />
<img />
<img />
js/金桥

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;
}

最新更新