頁面廣告隨意漂浮(打磚塊效果)

 頁面廣告隨意漂浮(打磚塊效果),代碼

 

  1. var xPos = 300; 
  2. var yPos = 200; 
  3. var step = 1; 
  4. var delay = 30; 
  5. var height = 0; 
  6. var Hoffset = 0; 
  7. var Woffset = 0; 
  8. var yon = 0; 
  9. var xon = 0; 
  10. var pause = true
  11. var interval; 
  12. img1.style.top = yPos; 
  13. function changePos() 
  14.     width = document.body.clientWidth; 
  15.     height = document.body.clientHeight; 
  16.     Hoffset = img1.offsetHeight; 
  17.     Woffset = img1.offsetWidth; 
  18.     img1.style.left = xPos + document.body.scrollLeft; 
  19.     img1.style.top = yPos + document.body.scrollTop; 
  20.     if (yon) 
  21.     { 
  22.         yPos = yPos + step; 
  23.     } 
  24.     else 
  25.     { 
  26.         yPos = yPos - step; 
  27.     } 
  28.     if (yPos < 0) 
  29.     { 
  30.         yon = 1; 
  31.         yPos = 0; 
  32.     } 
  33.     if (yPos >= (height - Hoffset)) 
  34.     { 
  35.         yon = 0; 
  36.         yPos = (height - Hoffset); 
  37.     } 
  38.     if (xon) 
  39.     { 
  40.         xPos = xPos + step; 
  41.     } 
  42.     else 
  43.     { 
  44.         xPos = xPos - step; 
  45.     } 
  46.     if (xPos < 0) 
  47.     { 
  48.         xon = 1; 
  49.         xPos = 0; 
  50.     } 
  51.     if (xPos >= (width - Woffset)) 
  52.     { 
  53.         xon = 0; 
  54.         xPos = (width - Woffset); 
  55.     } 
  56.  
  57. function start() 
  58.     img1.visibility = "visible"
  59.     interval = setInterval('changePos()', delay); 
  60. function pause_resume() 
  61.     if (pause) 
  62.     { 
  63.         clearInterval(interval); 
  64.         pause = false
  65.     } 
  66.     else 
  67.     { 
  68.         interval = setInterval('changePos()', delay); 
  69.         pause = true
  70.     } 
  71. start(); 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章