返回列表 發帖
用 JavaScript 改變背景圖的位置
To infinity and beyond!

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

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

TOP

返回列表 回復 發帖