Benutzer:CF/Schnee.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K ein paar Kleinigkeiten, sollte jetzt ein bisschen flüssiger laufen |
Ghost (Diskussion | Beiträge) K Fixes |
||
| Zeile 1: | Zeile 1: | ||
var letItSnow = | var letItSnow = | ||
{ | { | ||
snowPer100x100Pixels : 0.35, | snowPer100x100Pixels : 0.35, | ||
| Zeile 6: | Zeile 6: | ||
interval : null, | interval : null, | ||
loopindex : 0, | loopindex : 0, | ||
letItSnow : function(p) | letItSnow : function(p) | ||
{ | { | ||
| 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"; | ||
| Zeile 46: | Zeile 46: | ||
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 95: | Zeile 95: | ||
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"; | ||
Version vom 30. November 2025, 15:29 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");
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();