我创造了这样的东西
var pic = $('<img>').attr('src',someSrc);
$('body').append(pic);
我想在将此图像添加到 body 后立即将其动画化到屏幕上的某个位置,比如说:
$(pic).animate({top:'270px', left: '500px'}, 'slow');
但它不起作用。
最佳答案
我已经在浏览器中测试过了,但它似乎不能在代码片段中工作,可能你还需要在你的本地 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>
关于jquery - 如何为使用 jquery 创建的图像设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31368730/