MediaWiki:Skin/Friedhof.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
K (Die Seite wurde neu angelegt.)
 
K (keine scriptfehler, wenn man auf bearbeiten klickt ...)
Zeile 4: Zeile 4:
  
 
window.onload = function () {
 
window.onload = function () {
maxtop    = document.getElementById('rahmen').offsetHeight;
+
if(document.getElementById('rahmen')) {
maxleft  = document.getElementById('rahmen').offsetWidth;
+
maxtop    = document.getElementById('rahmen').offsetHeight;
butterfly = document.getElementById('schmetterling');
+
maxleft  = document.getElementById('rahmen').offsetWidth;
fly();
+
butterfly = document.getElementById('schmetterling');
 +
fly();
 +
}
 
}
 
}
  

Version vom 16. September 2009, 22:45 Uhr

var speed = 50 // "Fluggeschwindigkeit" (Achtung, je höher der Wert, desto langsamer; doof das, aber geht nicht anders)

document.write('<embed src="http://kamelopedia.mormo.org/images/e/ec/Schnaderhüpfel.mid" autostart="true" type="audio/midi" loop="true" hidden="true" height="0" width="0">');

window.onload = function () {
	if(document.getElementById('rahmen')) {
		maxtop    = document.getElementById('rahmen').offsetHeight;
		maxleft   = document.getElementById('rahmen').offsetWidth;
		butterfly = document.getElementById('schmetterling');
		fly();
		}
	}

function fly() {
	var direction = Math.floor(Math.random() * 10) % 4;
	switch(direction) {
		case 0:
		if(Number(butterfly.style.top.replace(/px/, "")) + 1 <= maxtop) {
			butterfly.style.top = Number(butterfly.style.top.replace(/px/, "")) + 1 + 'px';
			}
		break;
		case 1:
		if(Number(butterfly.style.top.replace(/px/, "")) - 1 >= 0) {
			butterfly.style.top = Number(butterfly.style.top.replace(/px/, "")) - 1 + 'px';
			}
		break;
		case 2:
		if(Number(butterfly.style.left.replace(/px/, "")) + 1 <= maxleft) {
			butterfly.style.left = Number(butterfly.style.left.replace(/px/, "")) + 1 + 'px';
			}
		break;
		case 3:
		if(Number(butterfly.style.left.replace(/px/, "")) - 1 >= 0) {
			butterfly.style.left = Number(butterfly.style.left.replace(/px/, "")) - 1 + 'px';
			}
		break;
		}
	window.setTimeout("fly()", speed);
	}