2016-08-04 7 views
0

У меня есть много видео на веб-сайте, и я смотрю на зависание, что парящая игра iframe. и на мышеловке он должен прекратить играть.JQuery Youtube Iframe Mouseenter и Mouseleave при зависании

Наведение и игра работает. Но Mouseleave не работает, и я не знаю, почему.

$(document).ready(function() { 
 
\t \t $(".youtube").each(function() { 
 
\t \t  $(this).css('background-image', 'url(//i.ytimg.com/vi/' + this.id + '/hqdefault.jpg)'); 
 
\t \t  $(document).delegate('#' + this.id, 'mouseenter', function() { 
 
\t \t \t \t if($(this).data('mouseenter')) { 
 
\t \t \t \t \t return; 
 
\t \t \t \t } 
 
\t \t \t \t $(this).data('mouseenter', true); 
 

 
\t \t  var iframe_url = "//www.youtube.com/embed/" + this.id + "?autoplay=1&autohide=1"; 
 
\t \t  if ($(this).data('params')) iframe_url += '&' + $(this).data('params'); 
 
\t \t  var iframe = $('<iframe/>', {'allowfullscreen':'allowfullscreen', 'frameborder': '0', 'src': iframe_url}) 
 
\t \t  $(this).append(iframe); 
 
\t \t  }); 
 
\t \t \t var playersrc=$('.youtube').attr('src'); 
 
\t \t }); 
 
\t \t });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

Нужна HTML, так как это связано с событиями мыши. Рабочий пример будет приятным, так как вы получили часть mouseenter. – zer00ne

ответ

0
$(document).delegate('#' + this.id, 'mouseleave', function() { 
      if($(this).data('mouseleave')) { 
       alert("not first time, but mouseleave is still detected"); 
       return; 
      } 
      alert("first time your cursor is quitting this iframe, mouseleave detected"); 
      $(this).data('mouseleave', true); 
     }); 

Это работает для меня!