Last active
December 8, 2017 10:43
-
-
Save Johann-S/241574c8fe8f5d0e560311da26327e38 to your computer and use it in GitHub Desktop.
An easter egg which will turn your page and your head ! (jQuery is needed)
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 ($) { | |
var kkeys = []; | |
var knm = ['38', '38', '40', '40', '37', '39', '37', '39', '66', '65']; | |
var knmTransitionClass = 'knm-transition'; | |
var $html = $('html'); | |
var transitionEnd = null; | |
var el = document.createElement('div'); | |
var transEndEventNames = { | |
WebkitTransition : 'webkitTransitionEnd', | |
MozTransition : 'transitionend', | |
OTransition : 'oTransitionEnd otransitionend', | |
transition : 'transitionend' | |
}; | |
for (var name in transEndEventNames) { | |
if (el.style[name] !== undefined) { | |
transitionEnd = transEndEventNames[name]; | |
} | |
} | |
// browser do not support transition | |
if (transitionEnd === null) { | |
return; | |
} | |
$('head').append([ | |
'<style>', | |
' /* konami fun */', | |
' .knm-transition {', | |
' -moz-transition: all 5000ms ease-in-out;', | |
' -o-transition: all 5000ms ease-in-out;', | |
' -webkit-transition: all 5000ms ease-in-out;', | |
' -webkit-transition: all 5000ms ease-in-out;', | |
' transition: all 5000ms ease-in-out;', | |
' }', | |
'</style>' | |
].join('')); | |
function nextRotation(currentRotation) { | |
if (currentRotation === null) { | |
return 45; | |
} | |
var arr = currentRotation.split('-'); | |
var degree = parseInt(arr[1], 10) + 45; | |
return degree === 360 ? 45 : degree; | |
} | |
$(window).on('keydown', function (e) { | |
kkeys.push(e.keyCode); | |
if (kkeys.toString() === knm.toString()) { | |
var currentRotation = null; | |
var currentClasses = $.makeArray($html[0].classList); | |
for (var i = 0; i < currentClasses.length; i++) { | |
if (currentClasses[i].indexOf('knm-') !== -1 && currentClasses[i] !== knmTransitionClass) { | |
currentRotation = currentClasses[i]; | |
$html.removeClass(currentClasses[i]); | |
break; | |
} | |
} | |
$html.one(transitionEnd, function () { | |
$html.removeClass(knmTransitionClass); | |
}); | |
var next = nextRotation(currentRotation); | |
$html.addClass(knmTransitionClass + ' knm-' + next).css({ | |
'-webkit-transform': 'rotate(' + next + 'deg)', | |
'-ms-transform': 'rotate(' + next + 'deg)', | |
transform: 'rotate(' + next + 'deg)' | |
}); | |
kkeys = []; // reset to continue | |
return; | |
} | |
if (kkeys.length === knm.length) { | |
kkeys = []; | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment