Как передать this в addEventListener?? Может кто-то оценить код и сказать что не так. При скролле страницы,если элемент с классом boxClass появляется в поле зрения, ему добавляется новый класс animateClass.
(function () {
var bind=function(fn, me){
return function(){
return fn.apply(me,arguments);
};
};
function Scroller(boxClass,animateClass){
this.boxClass=boxClass||"emergence";
this.animateClass=animateClass||"animated";
this.lastScroll=0;
this.handler=bind(this.scrollHandler,this);
};
Scroller.prototype.start=function(){
window.addEventListener('scroll',this.handler,false);
};
Scroller.prototype.stop=function(){
window.removeEventListener('scroll',this.handler,false);
};
Scroller.prototype.scrollHandler=function(){
var scrollTop=window.pageYOffset||document.documentElement.scrollTop;
if (scrollTop<this.lastScroll) {
return false;
};
var box=document.querySelectorAll("."+this.boxClass);
for (var i=box.length-1;i>=0;i--){
if (box[i].getBoundingClientRect().top<document.documentElement.clientHeight) {
box[i].classList.add(this.animateClass);
};
};
this.lastScroll=scrollTop;
};
this.Scroller=Scroller;
})();