返回列表 發帖

請問這個論壇上面的雲會動是怎麼做的?

請問這個論壇上面的雲會動是怎麼做的

用 JavaScript 改變背景圖的位置
To infinity and beyond!

TOP

(function(){function e(){var b=document.getElementById("header");if(b){var a="";if(b.currentStyle)a=[b.currentStyle.backgroundPositionX,b.currentStyle.backgroundPositionY].join(" ");else if(window.getComputedStyle)a=window.getComputedStyle(b,null).backgroundPosition;if(a!=""){a=a.split(" ");var c=parseInt(a[0],10);c+=d;if(c<0||c>100){d=-d;c+=d}b.style.backgroundPosition=[c,"% ",a[1]].join("")}}}var d=1;setInterval(e,1E3)})();
可以給沒有壓縮的版本參考看看嗎

TOP

(function () {
var move = 1;
function makemove() {
  var h = document.getElementById('header');
  if (!h) return;
  var bp = '';
  if (h.currentStyle) {
    bp = [h.currentStyle.backgroundPositionX, h.currentStyle.backgroundPositionY].join(' ');
  } else if (window.getComputedStyle) {
    bp = window.getComputedStyle(h, null).backgroundPosition;
  }
  if (bp == '') return;
  var bpArray = bp.split(' ');
  var bpLeft = parseInt(bpArray[0], 10);
  bpLeft += move;
  if (bpLeft < 0 || bpLeft > 100) {
    move = -move;
    bpLeft += move;
  }
  h.style.backgroundPosition = [bpLeft, '% ', bpArray[1]].join('');
}
setInterval(makemove, 1000);
})();
To infinity and beyond!

TOP

真佩服大大
小弟完全看不懂
可以註解一下哪一行是在做什麼的嗎

TOP

只能意會,不能言傳
To infinity and beyond!

TOP

返回列表 回復 發帖