Je m'essaye au js orienté objet mais là ça coince et je ne comprend vraiment pas pourquoi...
C'est une classe qui récupère les coordonnées de la souris, et la console Firefox renvoie une erreur : "this.getPos is not a function" dans la fonction init().
Code : Tout sélectionner
var Tracking = {
xy : [],
allpos : [],
event : null,
init : function(e) {
this.event = (!e) ? window.event : e;
this.getPos();
},
getPos : function() {
if (this.event.pageX || this.event.pageY) {
this.xy = [e.pageX, e.pageY];
} else if (this.event.clientX || this.event.clientY) {
this.xy = [
e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
e.clientY + document.body.scrollTop + document.documentElement.scrollTop
];
}
this.addPos();
alert(this.xy[0]+'-'+this.xy[1]);
},
addPos : function() {
this.allpos.push(this.xy);
}
};Code : Tout sélectionner
var Tracking = function() {
var xy, allpos, event;
function getPos() {
if (this.event.pageX || this.event.pageY) {
this.xy = [e.pageX, e.pageY];
} else if (this.event.clientX || this.event.clientY) {
this.xy = [
e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
e.clientY + document.body.scrollTop + document.documentElement.scrollTop
];
}
this.addPos();
alert(this.xy[0]+'-'+this.xy[1]);
}
function addPos() {
this.allpos.push(this.xy);
}
return {
init : function(e) {
this.xy = [];
this.allpos = [];
this.event = (typeof(e) == 'undefined') ? window.event : e;
this.getPos();
}
};
}();Code : Tout sélectionner
addEvent(window.document, 'mousemove', Tracking.init);
SVP auriez-vous une piste ou la solution à ce fichu problème ? Je suis complètement bloqué...
Merci beaucoup pour votre aide,