[英]Callback inside of an event listener for window is not working
(function(w,d,u){
var k = function(cb){
window.addEventListener('scroll',function(cb){
var scrll = this.scrollY;
if(cb){
cb.call(this,scrll);
}
},false);
};
return (window.scrollex=k);
})(this,document);
当我尝试运行它时,它根本无法工作。 我不断得到不确定的不是函数,这是为什么? 它是否与eventListener中的某些内容有关? 还是我在函数内部传递了参数? 我已经使用了很多次了,这简直太疯狂了,现在似乎在eventListener中遇到了问题。
谁能在这个问题上启发我?
现实生活中的例子
scrollr('element',{
max:500,
min:400,
swing:50,
name:"custom_event",
dir:"left",
trigger:"mousemove || scroll"
},function(t,a,c){
//t returns an object
//a returns the current position of the trigger if it is a mousemove or scroll
//c returns a boolean, which is if the element is inView of the viewport
});
window.addEventListener('scroll',function(cb){ <--cb is an event object
摆脱变量
window.addEventListener('scroll',function(){
============
根据您的评论,我认为您不需要致电
cb.call(this,scrll);
做就是了
cb.(scrll);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.