My code is giving me this error:
Uncaught TypeError: Cannot read property 'left' of undefined
Code:
function responsiveSlider() {
jQuery(".slider-bloc").each(function() {
var a = jQuery(this),
b = this;
if (1 != a.data("is_slider")) {
a.data("is_slider", 1);
var c = a.find(".nav-slider .item-nav"),
d = jQuery(a.find(".content-rel-slider")[0]),
e = jQuery(a.find(".content-abs-slider")[0]);
a.find(".item-slider").each(function(a) {
jQuery(this).attr("data-inc", a + 1)
}), a.find(".item-slider").clone().appendTo(e), a.find(".item-slider").clone().appendTo(e);
var f = a.find(".item-slider"),
g = a.hasClass("full-slider"),
h = 0,
i = function(a) {
e.css({
width: "100%"
}), g && f.css({
width: d.width()
}), e.css({
width: jQuery(f[0]).width() * f.length
});
Math.ceil(d.width() / jQuery(f[0]).width());
f.length * jQuery(f[0]).width() < d.width() ? e.css({
left: 0
}) : 0 == a && e.css({
left: -jQuery(f[0]).width()
})
},
j = function(b) {
var c = Math.ceil(d.width() / jQuery(f[0]).width());
durationanim = 2 >= c ? 300 : 800;
var g = jQuery(f[0]).width();
if (b + c - 1 >= f.length ? b = 0 : 0 > b && (b = f.length - c), f[b]) {
if (f.length * g < d.width()) return;
if (a.hasClass("moving")) return;
a.addClass("moving"), a.find(".item-slider").removeClass("current"), jQuery(a.find(".item-slider")[1]).addClass("current");
var i = "next",
j = 1,
k = e.position().left,
l = -g * c - g;
if (1 > b) {
i = "prev";
for (var m = 0; c > m; m++) jQuery(a.find(".item-slider")[f.length - 1]).prependTo(e);
k -= g * c, l = -g
} else j += c;
f = a.find(".item-slider"), h = 1;
var o = e.find(".item-slider.current").index();
if (!isMobile && c > 1) {
"next" == i ? (initforfirstslide = o, lastforfirstslide = o + c - 1, initforsecondslide = o + c, lastforsecondslide = o + 2 * c - 1) : (initforfirstslide = o - c, lastforfirstslide = o - 1, initforsecondslide = o, lastforsecondslide = o + c - 1);
for (var m = initforfirstslide; m <= lastforfirstslide; m++) {
var p = durationanim / 2,
q = durationanim / 2;
"next" == i ? movexfirstslide = -jQuery(f[m]).width() * (c - (m - o + 1)) / 4 : movexfirstslide = jQuery(f[m]).width() * (m - o + 1) / 4;
var r = new TimelineLite({
paused: !0
});
r.fromTo(jQuery(f[m]), p / 1e3, {
x: 0,
force3D: !0,
ease: Cubic.easeInOut
}, {
x: movexfirstslide,
force3D: !0,
ease: Cubic.easeInOut
}), r.to(jQuery(f[m]), q / 1e3, {
x: 0,
force3D: !0,
ease: Cubic.easeInOut
}), r.play()
}
for (var m = initforsecondslide; m <= lastforsecondslide; m++) {
var p = durationanim / 2,
q = durationanim / 2;
"next" == i ? movexsecondslide = jQuery(f[m]).width() * (m - o - c + 1) / 4 : movexsecondslide = jQuery(f[m]).width() * (m - o + 1) / 4;
var r = new TimelineLite({
paused: !0
});
r.fromTo(jQuery(f[m]), p / 1e3, {
x: 0,
force3D: !0,
ease: Cubic.easeInOut
}, {
x: movexsecondslide,
force3D: !0,
ease: Cubic.easeInOut
}), r.to(jQuery(f[m]), q / 1e3, {
x: 0,
force3D: !0,
ease: Cubic.easeInOut
}), r.play()
}
}
if (TweenMax.fromTo(e, durationanim / 1e3, {
left: k,
force3D: !0,
ease: n
}, {
left: l,
force3D: !0,
ease: n,
onComplete: function() {
if ("next" == i) {
h--;
for (var b = 0; c > b; b++) jQuery(a.find(".item-slider")[0]).appendTo(e);
e.css({
left: -g
})
}
f.removeClass("current"), jQuery(f[1]).addClass("current"), f = a.find(".item-slider"), a.removeClass("moving")
}
}), a.find(".nav-bullet").length > 0) {
var s = a.find(".nav-bullet .bullet").length - 1,
t = jQuery(a.find(".item-slider")[j]).attr("data-inc"),
u = t * s / (f.length / 4);.5 == u && (u = .4), currentbullet = Math.round(u), a.find(".nav-bullet .bullet").removeClass("current"), jQuery(a.find(".nav-bullet .bullet")[currentbullet]).addClass("current")
}
}
};
c.each(function() {
var a = jQuery(this);
a.on({
click: function() {
var b = a.hasClass("prev-button") ? 0 : 2;
return j(b), !1
}
})
}), _touchstart = !1, swipedirection = !1, _lastcoord = 0, coord = 0, initmoveposition = 0, touchmove = !1;
var k = new Hammer(b),
l = e.position().left,
m = l,
n = Cubic.easeInOut;
k.on("panstart", function(b) {
a.hasClass("moving") || (n = Strong.easeOut, l = e.position().left, m = l)
}), k.on("panend", function(b) {
a.hasClass("moving") || (2 == b.direction && j(1), 4 == b.direction && j(0), 1 == b.direction && TweenMax.to(e, .6, {
left: m,
force3D: !0,
ease: Strong.easeOut,
throwProps: !0
}))
}), k.on("panleft panright", function(b) {
a.hasClass("moving") || (0 == l && (l = e.position().left), TweenMax.to(e, .6, {
left: l + b.deltaX,
force3D: !0,
ease: Strong.easeOut,
throwProps: !0
}))
}), jQuery(window).on("resize", function() {
i(!1)
}), jQuery(a.find(".item-slider")[f.length - 1]).appendTo(e), e.css({
left: -jQuery(f[0]).width() * (h + 1)
}), f = a.find(".item-slider"), jQuery(f[1]).addClass("current"), h++, i(!0)
}
})}
This is the code of my responsive slider but sometimes it gave me the error
l = e.position().left, on this line, i tried to remove this line but then slider stops working, i don't know why sometimes it doesn't gave me the error please explain this to me will be very thankful to you.
Just place this line :
var e = jQuery(a.find(".content-abs-slider")[0]);
after or within
j = function(b) {
Related
it's hosted on github https://github.com/JulianLaval/canvas-particle-network
the particles are so blurry when i zoom in or on mobile screen
// particle.min.js hosted on GitHub
// Scroll down for initialisation code
! function(a) {
var b = "object" == typeof self && self.self === self && self || "object" == typeof global && global.global === global && global;
"function" == typeof define && define.amd ? define(["exports"], function(c) {
b.ParticleNetwork = a(b, c)
}) : "object" == typeof module && module.exports ? module.exports = a(b, {}) : b.ParticleNetwork = a(b, {})
}(function(a, b) {
var c = function(a) {
this.canvas = a.canvas, this.g = a.g, this.particleColor = a.options.particleColor, this.x = Math.random() * this.canvas.width, this.y = Math.random() * this.canvas.height, this.velocity = {
x: (Math.random() - .5) * a.options.velocity,
y: (Math.random() - .5) * a.options.velocity
}
};
return c.prototype.update = function() {
(this.x > this.canvas.width + 20 || this.x < -20) && (this.velocity.x = -this.velocity.x), (this.y > this.canvas.height + 20 || this.y < -20) && (this.velocity.y = -this.velocity.y), this.x += this.velocity.x, this.y += this.velocity.y
}, c.prototype.h = function() {
this.g.beginPath(), this.g.fillStyle = this.particleColor, this.g.globalAlpha = .7, this.g.arc(this.x, this.y, 1.5, 0, 2 * Math.PI), this.g.fill()
}, b = function(a, b) {
this.i = a, this.i.size = {
width: this.i.offsetWidth,
height: this.i.offsetHeight
}, b = void 0 !== b ? b : {}, this.options = {
particleColor: void 0 !== b.particleColor ? b.particleColor : "#fff",
background: void 0 !== b.background ? b.background : "#1a252f",
interactive: void 0 !== b.interactive ? b.interactive : !0,
velocity: this.setVelocity(b.speed),
density: this.j(b.density)
}, this.init()
}, b.prototype.init = function() {
if (this.k = document.createElement("div"), this.i.appendChild(this.k), this.l(this.k, {
position: "absolute",
top: 0,
left: 0,
bottom: 0,
right: 0,
"z-index": 1
}), /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(this.options.background)) this.l(this.k, {
background: this.options.background
});
else {
if (!/\.(gif|jpg|jpeg|tiff|png)$/i.test(this.options.background)) return console.error("Please specify a valid background image or hexadecimal color"), !1;
this.l(this.k, {
background: 'url("' + this.options.background + '") no-repeat center',
"background-size": "cover"
})
}
if (!/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(this.options.particleColor)) return console.error("Please specify a valid particleColor hexadecimal color"), !1;
this.canvas = document.createElement("canvas"), this.i.appendChild(this.canvas), this.g = this.canvas.getContext("2d"), this.canvas.width = this.i.size.width, this.canvas.height = this.i.size.height, this.l(this.i, {
position: "relative"
}), this.l(this.canvas, {
"z-index": "20",
position: "relative"
}), window.addEventListener("resize", function() {
return this.i.offsetWidth === this.i.size.width && this.i.offsetHeight === this.i.size.height ? !1 : (this.canvas.width = this.i.size.width = this.i.offsetWidth, this.canvas.height = this.i.size.height = this.i.offsetHeight, clearTimeout(this.m), void(this.m = setTimeout(function() {
this.o = [];
for (var a = 0; a < this.canvas.width * this.canvas.height / this.options.density; a++) this.o.push(new c(this));
this.options.interactive && this.o.push(this.p), requestAnimationFrame(this.update.bind(this))
}.bind(this), 500)))
}.bind(this)), this.o = [];
for (var a = 0; a < this.canvas.width * this.canvas.height / this.options.density; a++) this.o.push(new c(this));
this.options.interactive && (this.p = new c(this), this.p.velocity = {
x: 0,
y: 0
}, this.o.push(this.p), this.canvas.addEventListener("mousemove", function(a) {
this.p.x = a.clientX - this.canvas.offsetLeft, this.p.y = a.clientY - this.canvas.offsetTop
}.bind(this)), this.canvas.addEventListener("mouseup", function(a) {
this.p.velocity = {
x: (Math.random() - .5) * this.options.velocity,
y: (Math.random() - .5) * this.options.velocity
}, this.p = new c(this), this.p.velocity = {
x: 0,
y: 0
}, this.o.push(this.p)
}.bind(this))), requestAnimationFrame(this.update.bind(this))
}, b.prototype.update = function() {
this.g.clearRect(0, 0, this.canvas.width, this.canvas.height), this.g.globalAlpha = 1;
for (var a = 0; a < this.o.length; a++) {
this.o[a].update(), this.o[a].h();
for (var b = this.o.length - 1; b > a; b--) {
var c = Math.sqrt(Math.pow(this.o[a].x - this.o[b].x, 2) + Math.pow(this.o[a].y - this.o[b].y, 2));
c > 120 || (this.g.beginPath(), this.g.strokeStyle = this.options.particleColor, this.g.globalAlpha = (120 - c) / 120, this.g.lineWidth = .7, this.g.moveTo(this.o[a].x, this.o[a].y), this.g.lineTo(this.o[b].x, this.o[b].y), this.g.stroke())
}
}
0 !== this.options.velocity && requestAnimationFrame(this.update.bind(this))
}, b.prototype.setVelocity = function(a) {
return "fast" === a ? 1 : "slow" === a ? .33 : "none" === a ? 0 : .66
}, b.prototype.j = function(a) {
return "high" === a ? 5e3 : "low" === a ? 2e4 : isNaN(parseInt(a, 10)) ? 1e4 : a
}, b.prototype.l = function(a, b) {
for (var c in b) a.style[c] = b[c]
}, b
});
// Initialisation
var canvasDiv = document.getElementById('particle-canvas');
var options = {
particleColor: '#888',
background: 'https://raw.githubusercontent.com/JulianLaval/canvas-particle-network/master/img/demo-bg.jpg',
interactive: true,
speed: 'medium',
density: 'high'
};
var particleCanvas = new ParticleNetwork(canvasDiv, options);
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#particle-canvas {
width: 100%;
height: 100%;
}
<html>
<head></head>
<body>
<div id="particle-canvas"></div>
</body>
</html>
what can i do to increase the resolution
I want to set contrast, saturation and hue in my image editor. for this i use fabric.js but it have only brightness option..
Here is the my fabric js code
(function() {
fabric.Object.prototype.transparentCorners = false;
var $ = function(id){return document.getElementById(id)};
console.log($);
function applyFilter(index, filter) {
console.log(filter);
var obj = canvas.getActiveObject();
obj.filters[index] = filter;
obj.applyFilters(canvas.renderAll.bind(canvas));
}
function applyFilterValue(index, prop, value) {
var obj = canvas.getActiveObject();
if (obj.filters[index]) {
obj.filters[index][prop] = value;
obj.applyFilters(canvas.renderAll.bind(canvas));
}
}
fabric.Object.prototype.padding = 5;
fabric.Object.prototype.transparentCorners = false;
var canvas = this.__canvas = new fabric.Canvas('c'),
f = fabric.Image.filters;
fabric.Image.fromURL('../lib/bg.png', function(img) {
canvas.backgroundImage = img;
canvas.backgroundImage.width = 400;
canvas.backgroundImage.height = 400;
});
canvas.on({
'object:selected': function() {
fabric.util.toArray(document.getElementsByTagName('input'))
.forEach(function(el){ el.disabled = false; })
var filters = ['brightness',];
// var filters = ['grayscale', 'invert', 'remove-white', 'sepia', 'sepia2',
// 'brightness', 'noise', 'gradient-transparency', 'pixelate',
// 'blur', 'sharpen', 'emboss', 'tint', 'multiply', 'blend'];
for (var i = 0; i < filters.length; i++) {
$(filters[i]).checked = !!canvas.getActiveObject().filters[i];
}
applyFilter(5, true && new f.Brightness({
brightness: parseInt($('brightness-value').value, 10)
}));
},
'selection:cleared': function() {
fabric.util.toArray(document.getElementsByTagName('input'))
.forEach(function(el){ el.disabled = true; })
}
});
fabric.Image.fromURL('../upload/Chrysanthemum.jpg', function(img) {
var oImg = img.set({ left: 50, top: 100, angle: 0 }).scale(0.9);
canvas.add(oImg).renderAll();
canvas.setActiveObject(oImg);
});
$('brightness').onclick = function () {
applyFilter(5, this.checked && new f.Brightness({
brightness: parseInt($('brightness-value').value, 10)
}));
};
$('brightness-value').onchange = function() {
applyFilterValue(5, 'brightness', parseInt(this.value, 10));
};
})();
Last year I wrote a HSL plugin which might be of use:
fabric.Image.filters.HSL = fabric.util.createClass(fabric.Image.filters.BaseFilter, {
type: 'HSL',
initialize: function(options) {
options || (options = {});
this.hue = options.hue || 0;
this.saturation = options.saturation || 0;
this.lightness = options.lightness || 0;
},
rgbToHsl: function(r, g, b) {
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0;
} else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return [h, s, l];
},
hslToRgb: function(h, s, l) {
var r, g, b;
if (s == 0) {
r = g = b = l;
} else {
function hue2rgb(p, q, t){
if (t < 0) t += 1;
if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t;
if (t < 1/2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return [r * 255, g * 255, b * 255];
},
applyTo: function(canvasEl) {
var context = canvasEl.getContext('2d'),
imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
data = imageData.data;
for (var i=0; i<data.length; i+=4)
{
// Convert RGB to HSL
var hsl = this.rgbToHsl(data[i], data[i+1], data[i+2]);
// Apply HSL values
if (this.hue ) hsl[0] = this.hue;
if (this.saturation) hsl[1] = this.saturation;
if (this.lightness ) hsl[2] = this.lightness;
// Convert HSL back to RGB
var rgb = this.hslToRgb(hsl[0], hsl[1], hsl[2]);
// Update data
data[i] = rgb[0];
data[i+1] = rgb[1];
data[i+2] = rgb[2];
}
context.putImageData(imageData, 0, 0);
},
toObject: function() {
return extend(this.callSuper('toObject'), {
hue: this.hue,
saturation: this.saturation,
lightness: this.lightness
});
}
});
Add to your page after FabricJS has loaded and call like this:
var hue = 1; // Range: 0 to 1
var brightness = 1; // Range: 0 to 1
var lightness = 1; // Range: 0 to 1
var filterHSL = new img.filters.HSL({
hue: hue,
saturation: saturation,
lightness: lightness
});
img.filters = [filterHSL];
img.applyFilters(canvas.renderAll.bind(canvas));
...where canvas is your FabricJS canvas object.
I hope this helps.
You can now do this with the latest Fabricjs release, 1.6.6
fabric.Image.filters.Contrast and fabric.Image.filters.Saturate were added in this release.
I made a fiddle to show you how to achieve it (note: change the applyFilter() function to achieve different filters):
DEMO
I've been asked to create the same ripple effect as the one found with the bit.ly 404 page: http://bit.ly/khgefiyueagf734
Javascript and canvas are pretty new to me and I am having this problem. When I change the image to one that I want. Not the fish one that is on the 404 page it renders the image as the same size as the fish and wont change.
Can you tell me how to change the size of the ship (bit.ly fish) image?
Here is the JS Fiddle: http://jsfiddle.net/UzpAw/8/
and Here is the javascript that comes with it:
(function() {
function F() {
if (g.getContext) {
var a, b = a = 0;
if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) a = document.documentElement.clientWidth, b = document.documentElement.clientHeight;
if (document.body && (document.body.clientWidth || document.body.clientHeight)) a = Math.max(a, document.body.clientWidth), b = Math.max(b, document.body.clientHeight);
a = [a, b];
e = a[1];
d = a[0] + 1;
r = Math.floor(0.5 * e);
i = e - r;
j = i - G;
g.setAttribute("width", d);
g.setAttribute("height",
e);
g.style.width = d + "px";
g.style.height = e + "px";
s = [Math.floor(0.75 * d), 0];
c = g.getContext("2d");
c.fillStyle = "#00022f"; //rgba(104,168,220,.8)
v()
}
}
function v() {
c.fillRect(0, i, d, e - j)
}
function m(a, b) {
if (!w) k.style.top = "-9999px", k.style.left = "-9999px",k.style.height = "20px", c.clearRect(0, j, d, e - j);
c.clearRect(s[0], s[1] - 5, n[0], n[1]);
a = a || Math.floor(0.6 * d);
b = b || 0;
b += r - 0.5 * n[1];
c.drawImage(k, a, b, n[0], n[1]);
s = [a, b];
w || (v(), w = !0)
}
function O() {
midPointY = Math.sin(h * 10 * P) * (o - h) * Q;
h <= o && (f[p] = [0, midPointY], h % 9 == 0 && h % 2 == 1 && (f[z] = [-1, midPointY], z++));
c.clearRect(0, j, d, e - j);
m(Math.floor(0.6 * d), h < o ? Math.floor(midPointY) : 0);
c.beginPath();
c.moveTo(0, i);
for (var a = [0, i], b = 0; b < t; b++) if (f[b]) {
b < p && (f[b][0] = f[b][0] * R - H, f[p - b + p] = [-f[b][0], f[b][1]]);
var q = f[b][0] + I,
A = f[b][1] + i;
c.bezierCurveTo((q - a[0]) / 2 + a[0], a[1], q - (q - a[0]) / 2, A, q, A);
a[0] = q;
a[1] = A
}
c.lineTo(d, i);
c.lineTo(d, e);
c.lineTo(0, e);
c.closePath();
c.fill();
h++;
h == o && (B = !1);
h >= o * 2 && clearInterval(C)
}
function D(a, b) {
if (!J) return !1;
b && c.clearRect(x, y, b.w, b.h);
a = a || E[0];
x = K[0];
y = K[1] + a.mt;
c.drawImage(l, Math.abs(a.l),
Math.abs(a.t), a.w, a.h, x, y, a.w, a.h)
}
function S() {
var a = -1,
b = 0,
c = E.length,
d;
clearInterval(L);
L = setInterval(function() {
b = ++a > c - 1 ? c * 2 - 2 - a : a;
d = E[b];
D(d, M);
M = d;
a >= c * 2 - 2 && (a = 0)
}, 200)
}
var u = function(a, b, c) {
var d = c,
c = function(b) {
d.call(a, b)
};
return a.attachEvent ? a.attachEvent("on" + b, c) : a.addEventListener(b, c, !1)
};
if (!window.getComputedStyle) window.getComputedStyle = function(a) {
return a.currentStyle
};
var t = 13,
Q = 0.3,
d = 960,
e = 600,
G = 30,
r = Math.floor(0.5 * e),
R = 1.01,
H = 20,
i = e - r,
j = i - G,
o = (t - 3) * 9,
p = Math.floor(t / 2),
I, g,
c, C, B = !1,
P = Math.PI / 180,
f, z, h, k, s = [Math.floor(0.75 * d), 0],
n = [236, 195],
w, l, L, J, M, K = [10, 10], // 75, 150
E = [{
h: 58,
w: 140,
t: 0,
l: 0,
mt: 10
}, {
h: 72,
w: 150,
t: -64,
l: 0,
mt: 0
}, {
h: 61,
w: 150,
t: -151,
l: 0,
mt: 30
}],
N = !1;
g = document.createElement("canvas");
g.getContext && (N = !0, document.body.removeChild(document.getElementById("ripple")), g.setAttribute("id", "ripple"), document.body.appendChild(g), k = document.getElementById("ship"));
//, l = document.getElementById("gull"), l.setAttribute("src", "/static/graphics/gulls-404.png")
N && (function() {
try {
if (fish.complete) m();
else if (parseInt(15, 5)) setTimeout(m, 1E3); // 15 IS: getComputedStyle(k).height
else throw "no ship";
} catch (a) {
u(k, "load", function() {
m()
})
}
u(document.getElementById("ripple-control"), "mouseover", function(a) {
if (g.getContext && !B) clearInterval(C), p = Math.floor(t / 2), I = a.pageX, z = 1, h = 0, f = [], f[0] = [H, 0], C = setInterval(O, 30), B = !0
});
u(window, "resize", function() {
F();
m();
v();
D()
})
}(), F());
(function() {
var a = 0,
b = document.getElementById("cloud1"),
c = document.getElementById("cloud2"),
e = parseInt(getComputedStyle(b).left, 10),
f = parseInt(getComputedStyle(c).left, 10);
setInterval(function() {
if (++a == 2) a = 0, e += 1, b.style.left = e + "px";
f += 1;
c.style.left = f + "px";
e > d + 50 && (e = -200);
f > d + 50 && (f = -100)
}, 50)
})()
})();
You have to hover over the blue to get the image to show but as you can see, the size of the ship is way too large. I need it to be: 183x116.
Thanks for the help :)
The size of the ship is controlled by the variable on line#110.
as the effect of bottom of this page
I tried several ways but have not succeeded
http://larealpari.com/?
function () {
(function (e) {
var n, r, i, s, o, u, a, f, l, c, h, p, d, v, m;
return e.gc.active = !0, s = parseInt(t.delay), n = parseInt(t.count), v = parseInt(t.width), h = 0, l = 0, c = 0, u = parseInt(t.height), p = s, o = !0, window.timeout = null, window.interval = null, a = 0, m = 0, d = function () {
var t, r, i;
return i = e(window).width() / e(window).height(), r = v / u, i > r ? (h = e(window).width(), t = Math.ceil(u * (h / v)), c = parseInt((t - e(window).height()) / 2), l = 0) : (t = e(window).height(), h = Math.ceil(v * (t / u)), l = parseInt((h - e(window).width()) / 2), c = 0), e("#frame").css({
"background-size": "" + h * n + "px " + t + "px",
"background-position": "-" + (a * h + l) + "px -" + c + "px"
})
})(jQuery
);
I'm currently trying to add this fun little crawling fly script to my website, and want to customize it so that you can kill it when it's clicked. The script automatically places the image right above the tag, and I can't seem to get my jQuery .click function below it.
This is the script that I put in the head (sorry it's minified, but the unminified version doesn't work for some reason)
/* 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)
})();
And I want to put this below it:
<script type="text/javascript">
$("#bedbug").click(function() {
alert("ARGHHH!!!!");
});
</script>
Eventually once it works, I'm going to have the click function do a lot more, but I just need to get it working first.
Thanks to all in advance, I appreciate all the assistance you guys (and gals) provide. Cheers!
It is not loaded when you try to reference it. Use on() to your advantage
$(document).on("click", "#bedbug", function() {
alert("ARGHHH!!!!");
});