gpt4 book ai didi

javascript - 如何防止图像动画穿过我的整个屏幕而不仅仅是我的容器?

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:07 25 4
gpt4 key购买 nike

我目前有一个脚本函数,它获取图像并创建动画,允许它从屏幕的一侧传递到另一侧。但是我只想让动画穿过我的容器,它明显小于屏幕尺寸。我如何更改代码以允许它执行此操作?

功能:

 <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 = $(window).width(), 更改为 screenWidth = $("div.container").width(),

关于javascript - 如何防止图像动画穿过我的整个屏幕而不仅仅是我的容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40516650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com