簡體   English   中英

為什么進入和退出事件無法在jquery中觸發?

[英]why enter and exit event not fire in jquery?

我正在使用來自github的 scroll插件,我的輸入和退出事件不觸發

這是我的代碼,檢查鏈接plnkr

$(function(){
    $('.t').on('scrollSpy:enter', function() {
        console.log('enter:', $(this).attr('id'));
    });

    $('.t').on('scrollSpy:exit', function() {
        console.log('exit:', $(this).attr('id'));
    });

    $('#container .t').scrollSpy();

})

您是否在動態添加滾動間諜? 如果是這樣,則必須使用以下$(document).on()方法。

  $(function(){
      $(document).on('scrollSpy:enter','.t',function(){
        console.log('enter:', $(this).attr('id'));
      });    
    });

這個插件可以檢查間諜元素是否在視口之外。 默認情況下,視口是$(window)。 你可以這樣做:

  1. 打開scroll.js文件
  2. 在第一個函數中找到以下代碼: var jWindow = $(window); 這是一個視口。
  3. 您可以將其更改為$('#container')或刪除它,並在jQuery加載后,在scroll.js之前在html頭部分中將其初始化,如下所示:jWindow = $('#container')。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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