jquery 动画线条与动画gif 从左到右循环

jquery animated Line with animated gif from left to right loop

我设法让它工作,但我希望循环从 left:0 到 100%。想象你有一个圆圈,你让效果从一个点开始,然后效果绕着圆圈直到它再次开始(循环)。

<script>
$( window ).load(function() {
 (function loop(){
    $("#mark").animate({
    'marginLeft': '+=100%'
}, 5000);
$("#mark").animate({
    'marginLeft': '-=100%'
}, 5000, loop);
})();
});
</script>

你或许可以做类似的事情

 (function loop(){
     // Reset position to original 0%
     $("#mark").css('marginLeft', '0%');

     // animate it to 100%
     $("#mark").animate({
        'marginLeft': '100%'
     }, 5000, loop);
     // call itself again after it's done (5000 ms)
  })();

在您的 window 负载中,您甚至可能希望将 marginLeft 设置为 #mark 的宽度,使其看起来像是从侧面出现的。

问题是,为什么不使用 position + left 而不是边距?