如何使用jQuery在另一个div内移动一个div(包含图像) [英] How to move a div (containing image) inside another div using jquery

查看:474
本文介绍了如何使用jQuery在另一个div内移动一个div(包含图像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用效果和动画将图像div移动到其他div. 我该怎么办?

I need to move an image div to some other div with effects and animation. How I can do this?

我的代码:

    var div2Pos = $("#marque").position();
    var div2Width = $("#marque").css("width");
    var div2Height = $("#marque").css("height");

    $("#img-div").animate({'left':div2Pos.left, 'width':div2Width, 'height':div2Height}, 1000);

其中"#marque"是我的目标div,而#image-div"是我的原始div

where '#marque' is my destination div and '#image-div' is my original div

预先感谢

推荐答案

您需要使元素absalut使其动画到目标的absalout位置,并在动画结束时删除并附加elemt并删除absalut位置

you need to make the element absalut animate it to the absalout position of the destnation and when anaimation end remove and append the elemt and remove absalut position

          var des = $(".destnation").position();
        var el = $(".toMove");
        el.css("position", "absolute");
        el.animate({ top: des.top+"px" ,left :des.left+"px"}, 2000, undefined, function () {
            el.remove().appendTo(".destnation").css("position", "static");
        });

请参阅提琴手示例 http://jsfiddle.net/yamsalm/3U52z/

这篇关于如何使用jQuery在另一个div内移动一个div(包含图像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆