Skip to content

Instantly share code, notes, and snippets.

@hikari-no-yume
Last active December 21, 2015 04:49
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 hikari-no-yume/9d9d652e0e84816e4164 to your computer and use it in GitHub Desktop.
Save hikari-no-yume/9d9d652e0e84816e4164 to your computer and use it in GitHub Desktop.
spinning stars and other effects
// this is minified with http://lisperator.net/uglifyjs/ before being put inside [html]<script>...</script>[/html] in the News
(function () {
if (!String.prototype.hasOwnProperty('startsWith')) { // Chrome sucks so we have to polyfill this stuff
String.prototype.startsWith = function (str) {
return this.substr(0, str.length) === str;
};
}
if (!String.prototype.hasOwnProperty('endsWith')) {
String.prototype.endsWith = function (str) {
return this.substr(this.length - str.length) === str;
};
}
function doStars() {
var lastParent = null, speed = 1;
Array.prototype.filter.call(document.getElementsByTagName('img'), function (img) {
return img.src.endsWith("startechadmin.gif");
}).forEach(function (img) {
if (img.parentNode !== lastParent) {
speed = 1;
lastParent = img.parentNode;
}
img.style.animation = img.style.webkitAnimation = img.style.mozAnimation = 'spin ' + (speed++) + 's infinite linear';
img.style.transformOrigin = '8px 9px';
});
var style = document.createElement('style');
style.innerHTML = '@keyframes spin { from {transform:rotate(0deg);} to {transform:rotate(360deg);}}';
document.body.appendChild(style);
}
function wobbly(element) {
var numWobbles = 10;
var HTML = element.innerHTML;
HTML = HTML.replace(/\<script\>[\s\S]*\<\/script\>/gi, '');
var curTag = '';
var outHTML = '';
Array.prototype.forEach.call(HTML, function (c) {
if (!curTag) {
if (c === '<') {
curTag += c;
} else {
outHTML += '<span class=wobble' + Math.floor(Math.random() * numWobbles) + '>' + c + '</span>';
}
} else {
curTag += c;
if (c === '>') {
outHTML += curTag;
curTag = '';
}
}
});
element.innerHTML = outHTML;
var styles = document.createElement('style');
document.body.appendChild(styles);
window.setInterval(function () {
CSS = '';
for (var i = 0; i < numWobbles; i++) {
CSS += '.wobble' + i + ' { display: inline-block; transform: translate(' + (Math.random() * 3 - 1.5) + 'px, ' + (Math.random() * 3 - 1.5) + 'px); }';
}
styles.innerHTML = CSS;
}, 1000/30);
}
window.addEventListener('DOMContentLoaded', function () {
doStars();
Array.prototype.forEach.call(document.getElementsByClassName('gyeh'), function (element) {
wobbly(element);
});
}, false);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment