Last active
October 11, 2015 18:27
-
-
Save bergantine/3900752 to your computer and use it in GitHub Desktop.
Try and catch the button... non minified JS from http://www.romneytaxplan.com/. #demo #javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDirection(f, b) { | |
var h = f.width(), | |
d = f.height(), | |
a = (b.x - f.offset().left - h / 2) * (h > d ? d / h : 1), | |
c = (b.y - f.offset().top - d / 2) * (d > h ? h / d : 1), | |
g = Math.round((Math.atan2(c, a) * (180 / Math.PI) + 180) / 90 + 3) % 4; | |
switch (g) { | |
case 0: | |
return "top"; | |
case 1: | |
return "right"; | |
case 2: | |
return "bottom"; | |
default: | |
return "left"; | |
} | |
} | |
function reverse(a) { | |
switch (a) { | |
case "top": | |
return ["top", 1]; | |
case "bottom": | |
return ["top", -1]; | |
case "left": | |
return ["left", 1]; | |
default: | |
return ["left", -1]; | |
} | |
} | |
function sneak(f, b, h, d) { | |
var a = ~~f.css(h[0]).replace("px", ""), | |
c = h[1] * distance * (h[0] === "top" ? 1 : 2), | |
g = c > 0 ? h[0] === "top" ? 90 : 240 : h[0] === "top" ? -90 : -240; | |
a + ~~ (c * (h[0] === "top" ? 1 : xFactor)) + g > (h[0] === "top" ? wHeight() : wWidth()) ? f.css(h[0], h[0] === "top" ? "40px" : "100px") : a + ~~ (c * (h[0] === "top" ? 1 : xFactor)) - (h[0] === "top" ? 20 : 100) < 0 ? f.css(h[0], (h[0] === "top" ? wHeight() : wWidth()) + g - 40 + "px") : f.css(h[0], a + ~~ (c * (h[0] === "top" ? 1 : xFactor)) + "px"); | |
f.addClass("hovered skew" + b + (h[0] === "top" ? d : "")); | |
$body.addClass("laugh"); | |
count++; | |
(count === 6 || count === 3 && wWidth > 480) && $body.addClass("final"); | |
$.wait(300).then(function() { | |
f.removeClass("hovered skew" + b + (h[0] === "top" ? d : "")); | |
}); | |
$.wait(500).then(function() { | |
$body.removeClass("laugh"); | |
}); | |
} | |
function getDodgeSide(b, a) { | |
var c = b.width(); | |
return a.x - b.offset().left > c / 2 ? "right" : "left"; | |
} | |
$.wait = function(a) { | |
return $.Deferred(function(b) { | |
setTimeout(b.resolve, a); | |
}); | |
}; | |
var xFactor = 1.4, | |
win = $(window), | |
$body = $("body"), | |
wHeight = function() { | |
return win.height(); | |
}, | |
wWidth = function() { | |
return win.width(); | |
}, | |
distance = wWidth() < 481 ? 80 : 40, | |
button = $("button"), | |
count = 0; | |
$("button").on("mouseenter", function(d) { | |
var b = $(this), | |
f = getDirection(b, { | |
x: d.pageX, | |
y: d.pageY | |
}), | |
c = getDodgeSide(b, { | |
x: d.pageX, | |
y: d.pageY | |
}), | |
a = reverse(f); | |
sneak($(this), f, a, c); | |
}).on("click", function(d) { | |
var b = $(this), | |
f = getDirection(b, { | |
x: d.pageX, | |
y: d.pageY | |
}), | |
c = getDodgeSide(b, { | |
x: d.pageX, | |
y: d.pageY | |
}), | |
a = reverse(f); | |
sneak($(this), f, a, c); | |
}).addClass("on").one("mouseenter", function() { | |
$.wait(6000).then(function() { | |
$body.addClass("final"); | |
}); | |
}); | |
$(".copyright").on("click", "a", function(a) { | |
wWidth() < 480 && !$body.hasClass("final") && a.preventDefault(); | |
}); | |
win.on("resize", function() { | |
var a = ~~ ((button.offset().left + 100) / wWidth() * 100); | |
button.css({ | |
left: a + "%" | |
}); | |
wWidth() < 480 ? distance = 40 : distance = 80; | |
}); | |
yepnope({ | |
load: ["//platform.twitter.com/widgets.js", "//connect.facebook.net/en_US/all.js#xfbml=1&appId=123142237735444"] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment