2017-09-26 77 views
-1

我有一個jQuery中的腳本,將確定使用jquery中的滾動事件的節編號,但是當我在頁面上添加youtube iframe這個滾動事件不會觸發任何結果。無論如何,我可以解決這個問題嗎?任何幫助,將不勝感激。jQuery的滾動無法識別的頁面與YouTube的iframe

$(window).on('scroll', function() { 
 
    if ($(window).scrollTop() == 0) { 
 
    nextSection = 1; 
 
    $('.pre-num').html(nextSection); 
 
    console.log('still firing'); 
 
    } 
 
    if ($(window).scrollTop() == $section2.offset().top) { 
 
    nextSection = 2; 
 
    $('.pre-num').html(nextSection); 
 
    console.log('wont fire'); 
 
    } 
 
    if ($(window).scrollTop() == $section3.offset().top) { 
 
    nextSection = 3; 
 
    $('.pre-num').html(nextSection); 
 
    console.log('wont fire'); 
 
    } 
 
    if ($(window).scrollTop() > 3000) { 
 
    nextSection = 4; 
 
    $('.pre-num').html(nextSection); 
 
    console.log('wont fire'); 
 
    } 
 
});

+0

你介意提及/添加你正在使用的jQuery代碼嗎?什麼錯誤/警告你的瀏覽器JS控制檯顯示? – Junaid

+0

我使用了scrollify.js來使頁面中的每個部分在每次用戶向下滾動或向上滾動時都會捕捉。如果他們希望在頂部有一個YouTube圖標作爲英雄,那麼他們可以點擊開啓或關閉靜音,然後取消英雄區域中的無YouTube iframe。在圖像英雄區域一切正常工作,但如果他們選擇iframe可見的地方,那麼滾動事件將無法正常工作。我沒有檢查控制檯,也沒有警告。 – Frances

+0

$(窗口)。在( '滾動',函數(){ \t如果($(窗口).scrollTop()== 0){ \t nextSection = 1; '預NUM' \t $() html的(nextSection); \t的console.log( '仍然擊發'); \t} \t如果($(窗口).scrollTop()== $ section2.offset()頂部){ \t nextSection = 2 ;。 \t $( '前NUM ')HTML(nextSection); \t \t的console.log(' 不會火'); \t} \t if($(window).scrollTop()== $ section3.offset()。top){ \t nextSection = 3; \t $('。pre-num')。html(nextSection); \t console.log('wont fire'); ($(window).scrollTop()> 3000){ \t nextSection = 4; } \t} \t if \t $('。pre-num')。html(nextSection); \t console.log('wont fire'); \t} \t \t}); – Frances

回答

0

我現在看到的問題。當YouTube的iframe存在滾動事件正在工作,但不是offset().top,所以我只是將值更改爲偏移值的實數,所以而不是使用== $section2.offset().top我只是將它替換爲== 1213就像第一個條件。

謝謝@Junaid您的時間來對我的問題發表評論。