Benutzer:CF/Schnee.js
aus Stargate Wiki, dem deutschsprachigen Stargate-Lexikon
Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Extras → Internetspuren löschen … → Individuelle Auswahl → Den kompletten Cache löschen
var letItSnow = { snowPer100x100Pixels : 0.35, snowing : true, snow : [], interval : null, loopindex : 0, letItSnow : function(p) { if (!letItSnow.snowing) return; if (letItSnow.interval) letItSnow.stopIt(true); letItSnow.newSnow(true); letItSnow.interval = window.setInterval(letItSnow.loop, 50); }, loop : function() { for (var i=0; i<letItSnow.snow.length; ++i) if (letItSnow.snow[i].fall() && letItSnow.snow[i].remove()) letItSnow.snow.splice(i--, 1); if (! (letItSnow.loopindex = ((++(letItSnow.loopindex)) % 10))) letItSnow.newSnow(false); }, newSnow : function(inWindow) { var snowCount = Math.floor(window.innerHeight * window.innerWidth * letItSnow.snowPer100x100Pixels / 10000) - letItSnow.snow.length; for (var i=0; i<snowCount; ++i) letItSnow.snow.push(new letItSnow.Snow(inWindow)); }, Snow : function(inWindow) { this.vx = 0 + Math.random()* 0.051; this.vy = 2 + Math.random()* 5; this.dx = 5 + Math.random()*10; this.x = 0 + Math.random()*(window.innerWidth-30); this.y = 0 + Math.random()*window.innerHeight - (inWindow ? 0 : window.innerHeight); this.e = document.createElement("img"); this.e.src = "http://www.stargate-wiki.de/w/images/3/36/SGW-Schnee.png"; this.e.alt = "*"; this.e.style.width = "30px"; this.e.style.height = "30px"; this.e.style.position = "fixed"; this.e.style.left = Math.floor(this.x + Math.sin(this.y*this.vx)*this.dx)+"px"; this.e.style.top = Math.floor(this.y)+"px"; this.e.style.zIndex = "100"; document.body.appendChild(this.e); this.fall = function() { this.y += this.vy; if (this.y >= window.innerHeight) return true; this.e.style.left = Math.floor(this.x + Math.sin(this.y*this.vx)*this.dx)+"px"; this.e.style.top = Math.floor(this.y)+"px"; return false; }; this.remove = function() { document.body.removeChild(this.e); return true; }; }, stopIt : function(restart) { window.clearInterval(letItSnow.interval); if (!restart) letItSnow.snowing = false; for (var i=0; i<letItSnow.snow.length; ++i) letItSnow.snow[i].remove(); letItSnow.snow = []; }, addButton : function() { var w = document.getElementById("ca-watch"); if (!w) w = document.getElementById("ca-unwatch"); var node = mw.util.addPortletLink((skin=="vector" ? "p-views" : "p-cactions"), "#", "Schnee", "ca-snow", "Schneeanimation an- und ausschalten", "s", w); if (node) { node.onclick = function() { if (this.className == "selected") { this.className = ""; letItSnow.stopIt(); } else { this.className = "selected"; letItSnow.snowing = true; letItSnow.letItSnow(letItSnow); } }; if (skin == "vector") { var img = document.createElement("img"); img.alt = "Schneeanimation an- oder ausschalten"; img.src = "http://stargate-wiki.de/w/images/3/36/SGW-Schnee.png"; img.style.width = "24px"; img.style.height = "24px"; img.style.position = "relative"; img.style.top = "-5px"; node.firstChild.firstChild.replaceChild(img, node.firstChild.firstChild.firstChild); } } } }; // addOnloadHook( letItSnow.letItSnow("letItSnow") ); // solange noch nicht richtig eingebunden: //letItSnow.letItSnow("letItSnow"); // oder nur den Schalter letItSnow.addButton();