Jquery动画功能不动态图像

时间:2016-06-06 00:51:29

标签: javascript jquery html css jquery-animate

我正在尝试移动图像而这就是它。我似乎无法弄清楚为什么它给我的问题。这个想法是让图像在旋转一组图像的同时以方形图案进行。我想出那个部分,但现在我无法让图像生动。

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;
}

2 个答案:

答案 0 :(得分:1)

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

&#13;
&#13;
$(window).load(function(event) {
  //  while(true)
  //  {   
  $('#img_num').animate({
      "left": "+=50px"
    },
    "slow");
  //  }    
});
&#13;
#img_num {
  width: 250px;
  height: 250px;
  position: relative;
}
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

你在使用Jquery吗?

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

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

})