圖片漂浮代碼javascript

來源:互聯網
上載者:User

自己做的一個圖片漂浮代碼javascript,您可以自己調節速度。

 <!--代碼開始--> Code:
  1. <textarea rows="500" cols="500" id="Textarea1" name="Textarea1">   
  2. 將這個文字框設定得很大,以便瀏覽器視窗中出現捲軸。歡迎光臨北京網站建設師的部落格:http://hi.baidu.com/maxuu    
  3. </textarea>   
  4. <div id=float_icon style="visibility:hidden; position:absolute;left:0px;top:0px;">   
  5. <a href="www.baidu.com" target="_blank" alt="百度網站標誌"><img src="http://www.baidu.com/img/baidu_logo.gif"></a>   
  6. </div>   
  7.     
  8.     
  9. <script language="javascript">   
  10. var dirX=1,dirY=1;   
  11. var xPos = 0;var yPos = 0;   
  12. float_icon.style.top=0;   
  13. document.body.all.float_icon.style.left = 0;   
  14. document.body.all("float_icon").style.visibility = "visible";   
  15. window.setInterval("moveicon()",100);   
  16. function moveicon()   
  17. {   
  18. var speed=100; //每次移動100個像素,在這裡調節速度。值越大,速度越快。   
  19. xPos += speed*dirX;   
  20. yPos += speed*dirY;   
  21. float_icon.style.top =yPos + document.body.scrollTop;   
  22. float_icon.style.left =xPos + document.body.scrollLeft;   
  23. //下面的代碼實現當圖片碰撞到視窗的邊界時,改變移動的方向。   
  24. if (xPos<=0 || xPos+float_icon.offsetWidth>=document.body.clientWidth)   
  25. {dirX= -dirX;}   
  26. if (yPos<=0 || yPos + float_icon.offsetHeight>=document.body.clientHeight)   
  27. {dirY=-dirY;}   
  28. }   
  29. </script>   
 <!--代碼結束-->
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.