Created
May 14, 2018 10:16
-
-
Save fedek6/43598a48558a72db9fe9c7ff74de086a to your computer and use it in GitHub Desktop.
Glitch website using jQuery
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
$.fn.glitchMode = function() { | |
var glitches = { | |
/** | |
* Random color | |
*/ | |
color: function(e) { | |
var color ='#'+Math.random().toString(16).substr(2,6); | |
e.css('color', color ); | |
}, | |
/** | |
* Random scale | |
*/ | |
scale: function(e) { | |
var scale = 'scale3d(' + Math.floor((Math.random() * 3) + 1) + ',' + Math.floor((Math.random() * 3) + 1) + ',' + Math.floor((Math.random() * 3) + 1) + ')'; | |
e.css('transform', scale); | |
}, | |
/** | |
* Rotate | |
*/ | |
rotate: function(e) { | |
var rotate = 'rotate(' + Math.floor((Math.random() * 30) + 1) + 'deg)'; | |
e.css('transform', rotate); | |
}, | |
/** | |
* Random bg color | |
*/ | |
bgColor: function(e) { | |
var color ='#'+Math.random().toString(16).substr(2,6); | |
e.css('background-color', color ); | |
}, | |
}; | |
var keys = Object.keys(glitches); | |
// Loop through all elements | |
$('body > *') | |
.each( function() { | |
var r = Math.floor((Math.random() * 100) + 1); | |
var $this = $(this); | |
var threshold = Math.floor((Math.random() * 10) + 1); | |
for(var i=0; i<threshold; i++) { | |
glitches[keys[ keys.length * Math.random() << 0]]($this); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment