2017-09-26 82 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您的时间来对我的问题发表评论。