Skip to content

Instantly share code, notes, and snippets.

@fedek6
Created May 14, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedek6/43598a48558a72db9fe9c7ff74de086a to your computer and use it in GitHub Desktop.
Save fedek6/43598a48558a72db9fe9c7ff74de086a to your computer and use it in GitHub Desktop.
Glitch website using jQuery
$.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