我目前有一个脚本功能,该功能可以拍摄图像并创建动画,使其可以从屏幕的一侧传递到另一侧。但是我只希望动画经过我的容器,该容器明显小于屏幕尺寸。如何更改代码以使其执行此操作?

功能:

 <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(),

09-10 09:09
查看更多