body { margin: 0; }span { position: absolute; top: 15px; left: 5px; color: white; font: 12px Arial;} // We really want to disable window.open = function() {}; window.alert = function() {}; window.print = function() {}; window.prompt = function() {}; window.confirm = function() {};
// #killanim is only being used in lab full view, maybe we could // use it everywhere :D//if (window !== window.top && window.top.__stop_animations !== false) {if (window !== window.top && location.hash !== '#dontkillanim') { window.is_webkit = /(webkit)[ \/]([\w.]+)/.exec(window.navigator.userAgent.toLowerCase())
window.max_timer = window.is_webkit ? 2000 : 20
// Let's try to prevent user's from OOM'ing esp. in FX and Op. // First, we need to stop CSS Animations, after say 5s ? // // Ok, so i tried 5s, but there are some problems. Firstly, Firefox // and opera behave same. little improvement only. So making it 3s now. // // Tutorial: https://developer.mozilla.org/en/CSS/CSS_animations // Help: http://www.sitepoint.com/css3-animation-javascript-event-handlers
var pauseCSSAnimations = function() {
var stopCSSAnimations = function() { // Get the Body Element var body = document.getElementsByTagName('body')[0];
// We'll setup animationstart and animationiteration // events only. No need for animationend, cuz the // animation might be 30minutes long. animationiteration // cuz the animation might be .000002ms long.
// addEventListener is perfectly supported in IE9. // and we don't care about IE8 and below. Let those // browsers die in a fire!
body.addEventListener('webkitAnimationStart', stopAnimation, false); body.addEventListener('webkitAnimationIteration', stopAnimation, false); body.addEventListener('animationstart', stopAnimation, false); body.addEventListener('animationiteration', stopAnimation, false); };
// e is the event object bro ;) var stopAnimation = function(e) { // e.srcElement? lulz... var target_el = e.target; var e_type = e.type.toLowerCase(); if (e_type.indexOf('animationstart') !== -1 || e_type.indexOf('animationiteration') !== -1) { // LOL, we need to stop the animation now! // setInterval? lulz...
setTimeout(false, function() {
if (target_el.style.webkitAnimationPlayState !== 'paused') target_el.style.webkitAnimationPlayState = 'paused';
if (target_el.style.MozAnimationPlayState !== 'paused') target_el.style.MozAnimationPlayState = 'paused';
if (target_el.style.animationPlayState !== 'paused') target_el.style.animationPlayState = 'paused';
}, window.max_timer); } }
stopCSSAnimations();
};
// Next we need to pause/stop JS Animations
var pauseJSAnimations = function() {
// We need to override setInterval, setTimeout // in such a way, that all the calls register their // ids in an array and we can clear all the ids // after a given time. // // Don't trust me ? Lern2Google: // http://stackoverflow.com/a/11374151/1437328 // http://stackoverflow.com/a/8524313/1437328 // http://stackoverflow.com/a/8769620/1437328 // // 3rd one is pretty much the code you need! // // Thank you for building your trust in me now :D
window.setInterval = (function(oldSetInterval) { var registered = [];
var f = function() { var id; // .. this! var $this = this; // setInterval accepts n no. of args var args = arguments; // What if someone used the awesome Function.bind() ? // I am sure we want the awesome apply() then ;)
// this is my awesome brain usage. if first val is nonsense, // then don't register, heh. if (typeof args[0] !== 'function' && args[0] === false) { args = Array.prototype.slice.call(arguments); args = args.slice(1);
id = oldSetInterval.apply($this, args) } else { id = oldSetInterval.apply($this, args); registered.push(id); }
//console.log(registered); // Need to return the Interval ID return id; };
f.clearAll = function() { var r; while (r = registered.pop()) { clearInterval(r); } };
return f; })(window.setInterval);
window.setTimeout = (function(oldSetTimeout) { var registered = [];
var f = function() { var id; // .. this! var $this = this; // setInterval accepts n no. of args var args = arguments; // What if someone used the awesome Function.bind? // I am sure we want the awesome apply then ;)
// this is my awesome brain usage. if first val is nonsense, // then don't register, heh. if (typeof args[0] !== 'function' && args[0] === false) { args = Array.prototype.slice.call(arguments); args = args.slice(1);
id = oldSetTimeout.apply($this, args) } else { //console.log('lolzzzzz'); id = oldSetTimeout.apply($this, args); registered.push(id); }
//console.log(registered); // Need to return the Timeout ID return id; };
f.clearAll = function() { var r; while (r = registered.pop()) { clearTimeout(r); } };
return f; })(window.setTimeout);
setTimeout(false, function() { setTimeout.clearAll(); setInterval.clearAll(); }, window.max_timer);
// Time to Cancel rAF's Bro :) // You know things are harder when people are actually // using shims for rAF :/ So we need to test for vendors!
window.__requestAnimFrame = window.requestAnimationFrame || undefined; window.__cancelAnimFrame = window.cancelAnimationFrame || undefined; window.__vendors = ['webkit', 'moz', 'ms', 'o']; window.__registered_rafs = [];
// I can't think of a good way to cancel rAF's // So maybe lets use something similar to our other canceller's
window.__requestFrame = function(cb) { if (!window.__requestAnimFrame) return;
var req_id = window.__requestAnimFrame(cb); __registered_rafs.push(req_id);
return req_id; };
// Determine the proper VendorPrefixedFunctionName if (!window.__requestAnimFrame) { for (var x = 0; x
Try disturbing the particles with mouse
/* Text masked spring particles Author: Kushagra Gour a.k.a. Chin Chang (@chinchang457)*/
(function() { var H, Particle, W, animate, animationLoop, canvas, changeWord, colors, ctx, damping_constant, density, display_list, draw, getTextArray, init, last_time, min_distance, num_particles, onMouseMove, spring_constant, text_array, update;
window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { return window.setTimeout(callback, 1000 / 60); }; })();
canvas = null;
ctx = null;
num_particles = 500;
density = 8;
min_distance = 70;
text_array = [];
display_list = [];
last_time = null;
spring_constant = 0.2;
damping_constant = 0.08;
colors = ['#184DF4', '#F49A03', '#E01730', '#00A415'];
W = window.innerWidth;
H = window.innerHeight;
init = function(e) { var i, _i, _results; canvas = document.getElementById('c'); ctx = canvas.getContext('2d'); canvas.width = W; canvas.height = H; canvas.addEventListener('mousemove', onMouseMove); changeWord('code'); if (text_array.length) { _results = []; for (i = _i = 0; 0 num_particles; i = 0 h; i = _i += density) { for (j = _j = 0; 0 w; j = _j += density) { linear_index = (i * w + j) * 4; if (data[linear_index + 3] !== 0) { text_array.push({ x: j, y: i }); } } } return text_array; };
onMouseMove = function(e) { var child, d, dx, dy, mx, my, _i, _len, _results; mx = e.offsetX || e.pageX; my = e.offsetY || e.pageY; _results = []; for (_i = 0, _len = display_list.length; _i