我目前有一個腳本功能,它需要一個圖像,並創建一個動畫,允許它從屏幕的一側傳遞到另一側。但是我只是想讓動畫通過比我的容器小得多的屏幕尺寸。我如何更改代碼以允許它執行此操作?如何防止圖像動畫穿過我的整個屏幕而不僅僅是我的容器?
功能:
<script>
$(function() {
var img = $("#bus"),
width = img.get(0).width,
screenWidth = $(window).width(),
duration = 10000;
function animateBus() {
img.css("left", -width)
.animate({
"left": screenWidth
}, duration, animateBus);
}
animateBus();
});
</script>
這是我的集裝箱也:
div.container {
text-align: left;
width: 710px;
margin: 0 auto;
border: 12px solid black;
border-radius: 10px;
}
您是否嘗試用'screenWidth = $(「div.container」).width()''更改'screenWidth = $(window).width()'? – RizkiDPrast
當然我沒有工作 – user7048814