2017-05-03 3 views
0

スクロールがトリガーされるたびに、スクロール機能を無効にするフラグを使用しようとしています。私は.scroll()を他の機能と併用しているので、$(window).unbind("scroll");です。それでは、毎回機能が機能しなくなるのはなぜですか?スクロールごとにスクロールが発生しないようにします。

JS:

$(window).scroll(function() { 
     $("iframe").each(function() { 
      $this = $(this); 
      _src = $this.attr('src'); 
      _ID = $this.attr('id'); 
      _yPos = $(window).scrollTop(); 
      _thisHT = $this.height(); 
      _thisTop = $this.offset().top; 
      _thisBottom = _thisTop + _thisHT; 
      _Play = true; 

      if (_Play) { 
       if(_yPos > _thisTop*0.5 && _yPos < _thisBottom) {  
        $this.attr('src', _src + '&autoplay=1'); 
        _Play=false; 

       //$(window).unbind("scroll"); 
       } else { 
        $this.attr('src', _src); 

       } 
      } 
     }); 
    }); 
+3

'_Play'は常に真である私は$(window).scroll;_playを移動しなければならなかったし、私は偽/ increamentsの代わりに、真を使用(つまり、おそらくに動作しますが)。 – Huelfe

答えて

0

は、だから私はかなり明白だったsullotionを見つけました。

_play = '0'; 

$(window).scroll(function() { 


    $("iframe").each(function() { 
     $this = $(this); 
     _src = $this.attr('src'); 
     _ID = $this.attr('id'); 
     _yPos = $(window).scrollTop(); 
     _thisHT = $this.height(); 
     _thisTop = $this.offset().top; 
     _thisBottom = _thisTop + _thisHT; 
     if (_play === '0') { 
      if(_yPos > _thisTop*0.5 && _yPos < _thisBottom) {  
       _play = '1'; 
       $this.attr('src', _src + '&autoplay=1'); 





      //$(window).unbind("scroll"); 
      } else { 
       $this.attr('src', _src); 

      } 
     } 
    }); 
}); 
関連する問題