-1

我目前正在尝试将这个有趣的小爬虫脚本添加到我的网站,并希望对其进行自定义,以便在单击它时将其杀死。该脚本自动将图像放在标签的正上方,我似乎无法在其下方获取我的 jQuery .click 函数。

这是我放在头上的脚本(对不起,它被缩小了,但未缩小的版本由于某种原因不起作用)

/* 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>

最终,一旦它工作,我会让点击功能做更多的事情,但我只需要先让它工作。

提前感谢所有人,我感谢你们(和女孩)提供的所有帮助。干杯!

4

1 回答 1

2

当您尝试引用它时,它不会被加载。使用 on() 对您有利

$(document).on("click", "#bedbug", function() {
  alert("ARGHHH!!!!");
});
于 2013-01-23T20:06:27.173 回答