this is my javascript :
var tool = {
addEvent : function(element, eventName, callback){
if (element.addEventListener) {
element.addEventListener(eventName, callback, false);
} else if (element.attachEvent) {
element.attachEvent("on" + eventName, callback);
}
},
getPosition : function(el){
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
}
}
function getObj(){
this.a = document.getElementById('div');
this.b = document.getElementById('table');
this.func = function(){
var pos = tool.getPosition(this);
// how to insert this.b here
// i want to set this.b offset from this.a offset
}
tool.addEvent(this.a,'scroll',this.func);
}
var obj = new getObj();
how to modify this.func so whenever this.a is scrolling, this.b will be syncronized to this.a
this.b offset is get from this.a offset.
when i try :
this.func = function(){
var pos = tool.getPosition(this);
// value from pos will be set to this.b
console.log(this.b);
// how to insert this.b here
// i want to set this.b offset from this.a offset
}
this.b is undefined.