Jquery 动画功能不移动图像

Jquery animate function not moving image

我正在尝试移动图像,仅此而已。我似乎无法弄清楚为什么它会给我带来问题。这个想法是让图像在旋转一组图像的同时一直呈方形。我会弄清楚那部分,但现在我根本无法将图像设置为动画。

HTML:

  <body>
    <h1>Assignment 1</h1>
    <hr>

    <img id="img_num" src="images/img_num1.png" alt="Image."/>

    <hr>
    <a href="index.html">PAGE 1 | </a>
    <a href="page2.html">PAGE 2</a>

    <footer>Name | Student #</footer>
  </body>

JS:

$(window).onload(function(event)
{   
    while(true)
    {   
         $('#img_num').animate(
          {"left": "+=50px"},
          "slow");
    }    
});

CSS:

#img_num {
    width: 250px;
    height: 250px;
    position: relative;
}

您在使用 Jquery 吗?

试试这个Jquery...它会将它移出屏幕

$(document).ready(function() {
  $('#img_num').animate({
    "left": $(window).width()
  },1000);

})

.onload不是jQuery方法,使用.load();此外,while 循环似乎不是必需的

$(window).load(function(event) {
  //  while(true)
  //  {   
  $('#img_num').animate({
      "left": "+=50px"
    },
    "slow");
  //  }    
});
#img_num {
  width: 250px;
  height: 250px;
  position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
</script>

<body>
  <h1>Assignment 1</h1>
  <hr>

  <img id="img_num" src="http://placehold.it/300" alt="Image." />

  <hr>
  <a href="index.html">PAGE 1 | </a>
  <a href="page2.html">PAGE 2</a>

  <footer>Name | Student #</footer>
</body>