Benutzer:CF/Schnee.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
KKeine Bearbeitungszusammenfassung |
Ghost (Diskussion | Beiträge) K Fixes |
||
| (6 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
var letItSnow = | var letItSnow = | ||
{ | { | ||
snowPer100x100Pixels : 0. | snowPer100x100Pixels : 0.35, | ||
snowing : true, | snowing : true, | ||
snow : [], | snow : [], | ||
interval : null, | interval : null, | ||
loopindex : 0, | loopindex : 0, | ||
letItSnow : function(p) | letItSnow : function(p) | ||
{ | { | ||
| Zeile 12: | Zeile 12: | ||
if (letItSnow.interval) letItSnow.stopIt(true); | if (letItSnow.interval) letItSnow.stopIt(true); | ||
letItSnow.newSnow(true); | letItSnow.newSnow(true); | ||
letItSnow.interval = window.setInterval( | letItSnow.interval = window.setInterval(letItSnow.loop, 50); | ||
}, | }, | ||
loop : function() | loop : function() | ||
| Zeile 37: | Zeile 37: | ||
this.y = 0 + Math.random()*window.innerHeight - (inWindow ? 0 : window.innerHeight); | this.y = 0 + Math.random()*window.innerHeight - (inWindow ? 0 : window.innerHeight); | ||
this.e = document.createElement("img"); | this.e = document.createElement("img"); | ||
this.e.src = " | this.e.src = "https://stargatewiki.de/images/3/36/SGW-Schnee.png"; | ||
this.e.alt = "*"; | this.e.alt = "*"; | ||
this.e.style.width = "30px"; | this.e.style.width = "30px"; | ||
this.e.style.height = "30px"; | this.e.style.height = "30px"; | ||
this.e.style.position = " | 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.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.top = Math.floor(this.y)+"px"; | ||
this.e.style.zIndex = "100"; | this.e.style.zIndex = "100"; | ||
document.body.appendChild(this.e); | document.body.appendChild(this.e); | ||
this.fall = function() | this.fall = function() | ||
{ | { | ||
this.y += this.vy; | this.y += this.vy; | ||
if (this.y >= window.innerHeight) return true; | 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.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.top = Math.floor(this.y)+"px"; | ||
| Zeile 69: | Zeile 69: | ||
for (var i=0; i<letItSnow.snow.length; ++i) | for (var i=0; i<letItSnow.snow.length; ++i) | ||
letItSnow.snow[i].remove(); | letItSnow.snow[i].remove(); | ||
letItSnow.snow = | letItSnow.snow = []; | ||
}, | }, | ||
addButton : function() | addButton : function() | ||
{ | { | ||
var w = document.getElementById("ca-watch"); | var w = document.getElementById("ca-watch"); | ||
var skin = mw.config.get('skin') | |||
if (!w) w = document.getElementById("ca-unwatch"); | if (!w) w = document.getElementById("ca-unwatch"); | ||
var node = addPortletLink((skin=="vector" ? "p-views" : "p-cactions"), "#", "Schnee", "ca-snow", "Schneeanimation an- und ausschalten", "s", w); | var node = mw.util.addPortletLink((skin=="vector" ? "p-views" : "p-cactions"), "#", "Schnee", "ca-snow", "Schneeanimation an- und ausschalten", "s", w); | ||
if (node) | if (node) | ||
{ | { | ||
| Zeile 95: | Zeile 96: | ||
var img = document.createElement("img"); | var img = document.createElement("img"); | ||
img.alt = "Schneeanimation an- oder ausschalten"; | img.alt = "Schneeanimation an- oder ausschalten"; | ||
img.src = " | img.src = "https://stargatewiki.de/images/3/36/SGW-Schnee.png"; | ||
img.style.width = "24px"; | img.style.width = "24px"; | ||
img.style.height = "24px"; | img.style.height = "24px"; | ||
Aktuelle Version vom 1. Dezember 2025, 12:27 Uhr
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 = "https://stargatewiki.de/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");
var skin = mw.config.get('skin')
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 = "https://stargatewiki.de/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();