在Jetpack Infinity Scroll之后不能工作

时间:2017-10-09 08:29:51

标签: javascript jquery wordpress infinite-scroll jetpack

我有一个带有喷气背包无限滚动的wordpress页面,在我的所有帖子中都有一个youtubevideo在第一页,因为无限滚动加载页面2和3工作所有伟大的自动播放工作为youtube和所有这一切,但无限滚动工作和加载第2页来自youtube的视频不再播放更多内容只有第一页上的视频我能做什么我的javascript for autoplay看起来像这样:

        window.onload=function(){   
        var LoadVideo = function(player_id){    
            var Program = { 
                Init: function(){   
                    this.NewPlayer();   
                    this.EventHandler();    
                },  
                NewPlayer: function(){  
                    var _this = this;   
                    this.Player = new YT.Player(player_id, {    
                        events: {   
              'onStateChange': onPlayerStateChange, 
            }   
                    }); 
                    _this.Player.$element = $('#' + player_id); 
                },  
                Play: function(){   
                    if( this.Player.getPlayerState() === 1 ) return;
                    this.Player.playVideo();    
                },  
                Pause: function(){  
                    if( this.Player.getPlayerState() === 2 ) return;
                    this.Player.pauseVideo();   
                },  
                ScrollControl: function(){  
                    if( Utils.IsElementInViewport(this.Player.$element[0]) ) this.Play();
                    else this.Pause();  
                },  
                EventHandler: function(){   
                    var _this = this;   
                    $(window).on('scroll', function(){  
                        _this.ScrollControl();  
                    }); 
                }   
            };  
            var Utils = {   
                IsElementInViewport: function(el){  
                    if (typeof jQuery === "function" && el instanceof jQuery) el = el[0];   
                    var rect = el.getBoundingClientRect();  
                    return (    
                        rect.top >= 0 &&    
                        rect.left >= 0 &&   
                        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && 
                        rect.right <= (window.innerWidth || document.documentElement.clientWidth)   
                    );  
                }   
            };  

0 个答案:

没有答案