0
我试图将一些生成的元素定期滑入容器中。我试图使用jQuery的.animate()。将元素滑入容器
我直到现在:
<div id="mainContainer">
</div>
<div id="photoContainer" class="photocontclass" style="display:none">
<img id="image" src="@Url.Action("Photo_Read", new { Id = 1})" />
</div>
<script>
var photoId = 2;
$(document).ready(function() {
setInterval(function() { getPhoto() }, 3000);
});
function getPhoto() {
$("#photoContainer #image").attr("src", '@Url.Action("Photo_Read")' + '/' + photoId);
var $new = $('#photoContainer').clone().attr("id", "photoContainer" + photoId);
$('#timelineContainer').prepend($new);
$new.show('slow');
// do animation with animate...
$new.animate({
left:'-50%' // which properties should I have?
}, 2000, "swing", function() {
$(this).remove();
});
photoId++;
} </script>
<style>
.photocontclass {
display:inline;
margin:10px;
background-color:white;
padding:5px;
position:absolute;
}
#timelineContainer {
background-color:grey;
height:200px;
width:100%;
margin:10px;
padding:10px;
}
</style>
的$("#photoContainer")
应该从容器的右边进来,并在左侧出来......之后,它应该被删除...
我有些疑惑:
- 我应该在
mainContainer
,并在photoContainer
哪个CSS属性(位置,左,等等)? - 我应该将
photoContainer
放在mainContainer
的内部还是外部? - 哪些属性应该在动画方法中有?
可能的重复项:http://stackoverflow.com/q/15063125/86072。这个其他问题是否回答你的问题? – LeGEC 2013-04-10 10:37:47