如何使用jquery创建的图像动画?

时间:2015-07-12 14:17:38

标签: jquery html css jquery-animate

我创造了类似这样的东西

var pic = $('<img>').attr('src',someSrc);
$('body').append(pic);

我希望在将此图像添加到正文后立即将此图像设置为屏幕上的某个位置,让我们说:

$(pic).animate({top:'270px', left: '500px'}, 'slow');

但它没有用。

3 个答案:

答案 0 :(得分:0)

修改,更新

在属性选择器中的双引号之后,'添加'.css("position", "relative") pic.find()

尝试将"[src='" + someSrc + "']"与参数属性选择器.append()绑定到body并返回var someSrc = "http://lorempixel.com/200/200/technics"; var pic = $('<img>').attr('src',someSrc) .css("position","relative"); $("body").append(pic) .find("[src='" + someSrc + "']") .animate({ top: "270px", left: "500px" }, "slow");元素

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
&#13;
class User(AbstractBaseUser):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=30)
    email = models.EmailField(unique=True,max_length=75)
    test = models.CharField(max_length=20)

    USERNAME_FIELD = 'email'

    class Meta:
        managed = False
        db_table = 'auth_user'
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我在浏览中对此进行了测试,但似乎无法在代码段中使用,可能您还需要在本地html文件中对其进行测试

var img = $('<img src="http://static.adzerk.net/Advertisers/36e3fe661d1c4e38885da2fb2c98b1fc.png">');
img.css('position', 'absolute');
$('div#testDiv').append(img);
img.animate({ top: '270px', left: '500px' }, 'slow');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div id="testDiv"></div>

答案 2 :(得分:0)

您必须为图片添加“position:absolute”。

Sub test2()
    Dim Rws As Long, rng As Range, c As Range, sh As Worksheet, Fx As Range

    Rws = Cells(Rows.Count, "A").End(xlUp).Row
    Set rng = Range(Cells(14, "C"), Cells(Rws, "C"))
    Set sh = Sheets("Feuil2")

    For Each c In rng.Cells

        With sh

            Set Fx = .Columns(3).Find(what:=c, lookat:=xlWhole)

            If Not Fx Is Nothing Then

                c.Offset(0, -2).Range("A1:B1").Copy sh.Range("A" & Fx.Row)

            End If

        End With

    Next c

End Sub