2013-01-23 73 views
-1

我目前正試圖將這個有趣的小爬行飛行腳本添加到我的網站,並且想要對其進行自定義,以便在單擊它時可以將其殺死。該腳本自動將圖片放置在標籤的正上方,我似乎無法在其下方找到我的jQuery .click函數。需要在自動添加的腳本下面添加jQuery函數

這是我把頭上的腳本(它的精縮遺憾,但unminified版本不出於某種原因)

/* WWW: http://screen-bug.googlecode.com/git/index.html Released under WTFPL license.  */ 
(function() { 
    function y() { 
     0 >= --s && t(); 
     if (!j) { 
      var b; 
      if (b = 0 >= --u) d = 0, 50 > a.top ? d |= 1 : a.top > document.documentElement.clientHeight - 50 && (d |= 2), 50 > a.left ? d |= 4 : a.left > document.documentElement.clientWidth - 50 && (d |= 8), b = d; 
      if (b && (c %= 360, 0 > c && (c += 360), 15 < g(q[d] - c))) { 
       b = q[d] - c; 
       var k = 360 - c + q[d]; 
       f = g(b) < g(k) ? b : k; 
       u = 10; 
       l = 100; 
       m = 30 
      } 
      0 >= --l && (f = e(1, 150), l = h(40 * Math.random())); 
      if (0 >= --m) c += e(1, 10), m = h(10 * Math.random()); 
      else { 
       b = e(1, 5); 
       if (0 < f && 0 > b || 0 > f && 0 < b) b = -b; 
       f -= b; 
       c += b 
      } 
      r = c * v; 
      b = 2 * Math.cos(r); 
      k = 2 * -Math.sin(r); 
      a.style.top = (a.top += k) + "px"; 
      a.style.left = (a.left += b) + "px"; 
      n("rotate(" + (90 - c) + "deg)") 
     } 
    } 
    function e(b, a) { 
     var c = h(b + Math.random() * a); 
     return 0.5 < Math.random() ? c : -c 
    } 
    function t() { 
     j = !j; 
     s = e(50, 300); 
     j ? (a.src = "https://screen-bug.googlecode.com/git/fruitfly.png", a.id = "bedbug", document.addEventListener ? document.addEventListener("mousemove", p, !1) : document.attachEvent && document.attachEvent("onmousemove", p)) : (a.src = "https://screen-bug.googlecode.com/git/fruitfly.png", w()) 
    } 
    function w() { 
     document.removeEventListener ? document.removeEventListener("mousemove", p, !1) : document.detachEvent && document.detachEvent("onmousemove", p) 
    } 
    function p(b) { 
     b = b || window.event; 
     b.clientX ? (posx = b.clientX, posy = b.clientY) : b.pageX && (posx = b.pageX - (document.body.scrollLeft + document.documentElement.scrollLeft), posy = b.pageY - (document.body.scrollTop + document.documentElement.scrollTop)); 
     40 > g(a.top - posy) + g(a.left - posx) && (t(), w()) 
    } 
    var c = 90, 
     r = c * v, 
     f = 0, 
     q = { 
      1: 270, 
      2: 90, 
      4: 0, 
      8: 180, 
      5: 315, 
      9: 225, 
      6: 45, 
      10: 135 
     }, d = 0, 
     u = 10, 
     m = 0, 
     l = 0, 
     s = 50 * Math.random(), 
     j = !1, 
     a = null, 
     n = void 0, 
     x = { 
      Moz: function (b) { 
       a.style.MozTransform = b 
      }, 
      Webkit: function (b) { 
       a.style.WebkitTransform = b 
      }, 
      O: function (b) { 
       a.style.OTransform = b 
      }, 
      Ms: function (b) { 
       a.style.msTransform = b 
      }, 
      Khtml: function (b) { 
       a.style.KhtmlTransform = b 
      }, 
      w3c: function (b) { 
       a.style.transform = b 
      } 
     }, h = Math.round, 
     g = Math.abs, 
     v = Math.PI/180; 
    setTimeout(function() { 
     a = document.createElement("img"); 
     a.src = "https://screen-bug.googlecode.com/git/fruitfly.png"; 
     (new Image).src = "https://screen-bug.googlecode.com/git/fruitfly.png"; 
     a.style.position = "fixed"; 
     a.style.zIndex = "99"; 
     a.top = e(50, document.documentElement.clientHeight - 50); 
     a.top = 0 < a.top ? a.top : -a.top; 
     a.left = e(50, document.documentElement.clientWidth - 50); 
     a.left = 0 < a.left ? a.left : -a.left; 
     a.style.top = a.top + "px"; 
     a.style.left = a.left + "px"; 
     document.body.appendChild(a); 
     m = h(10 * Math.random()); 
     l = h(40 * Math.random()); 
     "transform" in a.style && (n = x.w3c); 
     var b = ["Moz", "Webkit", "O", "Ms", "Khtml"]; 
     for (i in b) if (b[i] + "Transform" in a.style) { 
      n = x[b[i]]; 
      break 
     } 
     c = e(0, 360); 
     n && setInterval(y, 100) 
    }, 2E3) 
})(); 

我想把這在它下面:

<script type="text/javascript"> 
$("#bedbug").click(function() { 
    alert("ARGHHH!!!!"); 
}); 
</script> 

最終,一旦它工作,我將有點擊功能做更多,但我只需要讓它工作的第一。

感謝所有提前,我感謝你們(和gals)提供的所有幫助。乾杯!

回答

2

當您嘗試引用它時,它不會被加載。使用()以您的優勢

$(document).on("click", "#bedbug", function() { 
    alert("ARGHHH!!!!"); 
}); 
+0

它的工作原理!謝啦 –