簡體   English   中英

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

.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> 

您正在使用Jquery嗎?

試試這個Jquery ...它將把它移出屏幕

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

})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM