2016-08-04 3 views
0

나는 웹 사이트에 많은 비디오를 가지고 있는데, 마우스를 올리면 마우스가 올라와있는 iframe이 재생됩니다. 그리고 mouseleave에서 재생을 멈춰야합니다.Jquery Youtube 마우스를 올리면 마우스가 움직입니다.

호버 앤 플레이가 작동합니다. 그러나 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); 
     }); 

이 나를 위해 작동!

관련 문제