forked from netlify/petsofnetlify
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript.js
33 lines (29 loc) · 903 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Shuffle elements method
* @param elems
*/
function shuffle(elems) {
allElems = (function(){
var ret = [], l = elems.length;
while (l--) { ret[ret.length] = elems[l]; }
return ret;
})();
var shuffled = (function(){
var l = allElems.length, ret = [];
while (l--) {
var random = Math.floor(Math.random() * allElems.length),
randEl = allElems[random].cloneNode(true);
allElems.splice(random, 1);
ret[ret.length] = randEl;
}
return ret;
})(), l = elems.length;
while (l--) {
elems[l].parentNode.insertBefore(shuffled[l], elems[l].nextSibling);
elems[l].parentNode.removeChild(elems[l]);
}
}
document.addEventListener("DOMContentLoaded", function(event) {
// on load shuffle everything
shuffle( document.getElementsByClassName('pet') );
});