Hallo zusammen,
bin ein blutiger Anfänger was Javascript betrifft. Mein Wissen besteht nur aus einem Buch das sich "Ajax" nennt. Und zwar soll ich ein Schneefeld programmieren, das den Mauszeiger als Ursprungspunkt hat und dieser soll sich natürlich mit bewegen sobald man die Maus bewegt. Nur hab ich jetzt das Problem das die Variable s nicht der function gen übergeben wird bzw. ich den Fehler "s is undefined" bekomme. Aber ich weiss beim besten Willen nicht wieso das so ist.
Würd mich über eine Antwort freuen.
Gruss
Marc
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Schneefeld.aspx.cs" Inherits="Schneefeld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Schneefeld</title>
<script src="x_browser.js" type="text/javascript"></script>
</head>
<body onload="start()" overflow: "hidden">
<script type="text/javascript">
var name;
var ausgabe = "";
var anzahlFlocken = 20;
stern = function(nm,x,y)
{
this.dx= 0;
this.dy = 0;
this.pos_x = x;
this.pos_y = y;
this.name = nm;
this.bew = 10;
this.ix = 0;
this.iy = 0;
this.obj = document.getElementById(this.name);
}
stern.prototype.posXY = function(x,y){
this.pos_x = x;
this.pos_y = y;
}
stern.prototype.delta = function(angle){
this.dy = Math.sin(angle) * this.bew;
this.dx = Math.cos(angle) * this.bew;
}
function start(){
if (window.Event) {
document.captureEvents(Event.MOUSEMOVE);
window.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = koo;
}
koo = function(e) {
if (document.all) {
x_koo = event.clientX;
y_koo = event.clientY;
} else{
x_koo = e.clientX;
y_koo = e.clientY;
}
h_x = x_koo;
h_y = y_koo;
}
stern.prototype.flug = function(){
this.ix = this.ix +0.16;
this.iy = this.iy +0.16;
this.pos_x = this.pos_x + this.dx;
this.pos_y = this.pos_y + this.dy;
if(this.pos_x>((hx)) || this.pos_x<0 || this.pos_y<0 || this.pos_y>((hy)))
{
this.pos_x = h_x;
this.pos_y = h_y;
this.ix = 0;
this.iy = 0;
}
this.obj.width = this.ix;
this.obj.height = this.iy;
this.obj.style.top = this.pos_y+'px';
this.obj.style.left = this.pos_x+'px';
}
var h_y = (xClientHeight()/2);
var h_x = (xClientWidth()/2);
var hy = xClientHeight();
var hx = xClientWidth();
var s = new Array();
for (var i = 0; i < anzahlFlocken; i++){
name = "stern"+i;
ausgabe = "<img src=\"flocke.gif\" style=\"position: absolute\; top:" + h_y + "px\; left:" + h_x + "px\;\"id=\"" + name + "\"/>";
document.write(ausgabe);
s = gen(i);
}
function gen(i){
alert(i);
s.push(new stern(name,h_x,h_y));
s[i].delta(Math.round(Math.random()*360));
setTimeout("s["+i+"].flug()", 1+ (Math.random() * 10));
}
</script>
</body>
</html>