Advertisement
Guest User

Fugitive button - romneytaxplan.com

a guest
Oct 16th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getDirection(e, t) {
  2.     var n = e.width(),
  3.         r = e.height(),
  4.         i = (t.x - e.offset().left - n / 2) * (n > r ? r / n : 1),
  5.         s = (t.y - e.offset().top - r / 2) * (r > n ? n / r : 1),
  6.         o = Math.round((Math.atan2(s, i) * (180 / Math.PI) + 180) / 90 + 3) % 4;
  7.     switch (o) {
  8.         case 0:
  9.             return "top";
  10.         case 1:
  11.             return "right";
  12.         case 2:
  13.             return "bottom";
  14.         default:
  15.             return "left"
  16.     }
  17. }
  18. function reverse(e) {
  19.     switch (e) {
  20.         case "top":
  21.             return ["top", 1];
  22.         case "bottom":
  23.             return ["top", - 1];
  24.         case "left":
  25.             return ["left", 1];
  26.         default:
  27.             return ["left", - 1]
  28.     }
  29. }
  30. function sneak(e, t, n, r) {
  31.     var i = ~~e.css(n[0]).replace("px", ""),
  32.         s = n[1] * distance * (n[0] === "top" ? 1 : 2),
  33.         o = s > 0 ? n[0] === "top" ? 90 : 240 : n[0] === "top" ? -90 : -240;
  34.     i + ~~ (s * (n[0] === "top" ? 1 : xFactor)) + o > (n[0] === "top" ? wHeight() : wWidth()) ? e.css(n[0], n[0] === "top" ? "40px" : "100px") : i + ~~ (s * (n[0] === "top" ? 1 : xFactor)) - (n[0] === "top" ? 20 : 100) < 0 ? e.css(n[0], (n[0] === "top" ? wHeight() : wWidth()) + o - 40 + "px") : e.css(n[0], i + ~~ (s * (n[0] === "top" ? 1 : xFactor)) + "px");
  35.     e.addClass("hovered skew" + t + (n[0] === "top" ? r : ""));
  36.     $body.addClass("laugh");
  37.     count++;
  38.     (count === 6 || count === 3 && wWidth > 480) && $body.addClass("final");
  39.     $.wait(300).then(function () {
  40.         e.removeClass("hovered skew" + t + (n[0] === "top" ? r : ""))
  41.     });
  42.     $.wait(500).then(function () {
  43.         $body.removeClass("laugh")
  44.     })
  45. }
  46. function getDodgeSide(e, t) {
  47.     var n = e.width();
  48.     return t.x - e.offset().left > n / 2 ? "right" : "left"
  49. }
  50. $.wait = function (e) {
  51.     return $.Deferred(function (t) {
  52.         setTimeout(t.resolve, e)
  53.     })
  54. };
  55. var xFactor = 1.4,
  56.     win = $(window),
  57.     $body = $("body"),
  58.     wHeight = function () {
  59.         return win.height()
  60.     }, wWidth = function () {
  61.         return win.width()
  62.     }, distance = wWidth() < 481 ? 80 : 40,
  63.     button = $("button"),
  64.     count = 0;
  65. $("button").on("mouseenter", function (e) {
  66.     var t = $(this),
  67.         n = getDirection(t, {
  68.             x: e.pageX,
  69.             y: e.pageY
  70.         }),
  71.         r = getDodgeSide(t, {
  72.             x: e.pageX,
  73.             y: e.pageY
  74.         }),
  75.         i = reverse(n);
  76.     sneak($(this), n, i, r)
  77. }).on("click", function (e) {
  78.     var t = $(this),
  79.         n = getDirection(t, {
  80.             x: e.pageX,
  81.             y: e.pageY
  82.         }),
  83.         r = getDodgeSide(t, {
  84.             x: e.pageX,
  85.             y: e.pageY
  86.         }),
  87.         i = reverse(n);
  88.     sneak($(this), n, i, r)
  89. }).addClass("on").one("mouseenter", function () {
  90.     $.wait(6e3).then(function () {
  91.         $body.addClass("final")
  92.     })
  93. });
  94. $(".copyright").on("click", "a", function (e) {
  95.     wWidth() < 480 && !$body.hasClass("final") && e.preventDefault()
  96. });
  97. win.on("resize", function () {
  98.     var e = ~~ ((button.offset().left + 100) / wWidth() * 100);
  99.     button.css({
  100.         left: e + "%"
  101.     });
  102.     wWidth() < 480 ? distance = 40 : distance = 80
  103. });
  104. yepnope({
  105.     load: ["//platform.twitter.com/widgets.js", "//connect.facebook.net/en_US/all.js#xfbml=1&appId=123142237735444"]
  106. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement