0
我試圖使用一個標誌來防止滾動觸發每次滾動觸發功能。 $(window).unbind("scroll");
因爲我使用.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);
}
}
});
});
'_Play'總是正確的。 – Huelfe