第一
detect if autoplay is supported
,然后:
$(function() {
let $container = $('#top-banner-vid .video-container > .col');
let $video = $.parseHTML('<video class="embed-responsive video-bg" poster="12-sunrise-picture.jpg" autoplay loop muted><source class="embed-responsive-item" src="http://www.icutpeople.com/wp-content/themes/icutpeople/assets/video/waynesworld.mp4" type="video/mp4">Your browser does not support the video tag. Please update your browser to enjoy the full features of this website.</video>');
let $image = $.parseHTML('<img src="12-sunrise-picture.jpg"/>');
function addVideo() {
$container.append($video);
}
function addImage() {
$container.append($image);
$image.on('click', () => {
$container.empty().append($video);
});
}
if (autoplaySupported()) {
addVideo();
} else {
addImage();
}
}();
当然,加载后他们必须再次单击它,因此您可能需要尝试
use the click event to also start the video
,这可能很棘手。