簡體   English   中英

窗口的事件偵聽器內部的回調不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM