2017-08-31 122 views
0

尋找比這更好的解決方案:jQuery的:播放視頻懸停

$(".video-post").hover(function() {  
    $(this).find("video").get(0).play(); 
}, function() { 
    $(this).find("video").get(0).pause();  
}); 

- >它的工作原理,但會導致鉻錯誤: 拋出:DOMException:播放()請求被調用中斷暫停() 。

Theres關於這方面的一些文章,但似乎找不到任何簡單的答案。 https://developers.google.com/web/updates/2017/06/play-request-was-interrupted

回答

0

嘗試:

$(document).ready(function() { 
    $(".video-post").hover(function() { 
     $(this).find("video")[0].play(); 
    }, function() { 
     var el = $(this).find("video")[0]; 
     el.pause(); 
     el.currentTime = 0; 
    }); 
});