$(document).ready(function(){
"use strict"; var srctext; $('.elementor-video-iframe').each(function(i, elem) { srctext = $(elem).attr('src');
if(srctext.match(/youtube/)){
if(srctext.match(/autoplay/)){ srctext = srctext.replace("&autoplay=0",""); srctext = srctext.replace("autoplay=0",""); srctext = srctext.replace("&autoplay=1",""); srctext = srctext.replace("autoplay=1",""); $(this).attr('src', srctext); }
if(srctext.match(/enablejsapi/)){
srctext = srctext.replace("enablejsapi=0","enablejsapi=1"); $(this).attr('src', srctext);
}else{ srctext = srctext + "&enablejsapi=1"; $(this).attr('src', srctext); }
//iosで自動再生するために必須 srctext = srctext + "&playsinline=1"; $(this).attr('src', srctext);
}
}); });
$(function() { "use strict";
if($('.elementor-video-iframe').length){
$('.elementor-video-iframe').on('inview', function(event, isInView) {
// 要素がウィンドウの表示領域に現れたときに実行する処理 var srctext; var $playerWindow;
if (isInView) {
srctext = $(this).attr('src');
if(srctext.match(/youtube/) && !srctext.match(/autoplay=1/)){
$playerWindow = $(this)[0].contentWindow; $playerWindow.postMessage('{"event":"command","func":"'+"playVideo"+'","args":""}', '*'); $playerWindow.postMessage('{"event":"command","func":"'+"mute"+'","args":""}', '*');
}
}else{
$playerWindow = $(this)[0].contentWindow; $playerWindow.postMessage('{"event":"command","func":"'+"pauseVideo"+'","args":""}', '*');
}
});
} });
コメントを残す