在片段中,我通过延迟加载加载了 Wistia 嵌入式视频。使用autoPlay=true
,我无法在视频开始播放时取消静音。
muted=false
似乎不像这里的文档中描述的那样工作。
关于如何在自动播放为真时将其静音的任何想法?
(function () {
const wistia = document.querySelectorAll(".wistia");
for (let i = 0; i < wistia.length; i++) {
let source = `https://embed-ssl.wistia.com/deliveries/${wistia[i].dataset.thumb}.jpg`
let image = new Image();
image.src = source;
image.addEventListener("load", (function () {
wistia[i].appendChild(image);
})(i)
);
wistia[i].addEventListener("click", function () {
let iframe = document.createElement("iframe");
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("allowfullscreen", "");
iframe.setAttribute("mozallowfullscreen", "");
iframe.setAttribute("webkitallowfullscreen", "");
iframe.setAttribute("oallowfullscreen", "");
iframe.setAttribute("msallowfullscreen", "");
iframe.setAttribute('src', `//fast.wistia.net/embed/iframe/${this.dataset.embed}?videoFoam=true&autoPlay=true`);
this.innerHTML = "";
this.appendChild(iframe);
});
}
})();
.wistia {
background-color: #000;
margin-bottom: 30px;
position: relative;
padding-top: 56.25%;
overflow: hidden;
cursor: pointer;
}
.wistia img {
width: 100%;
top: 0; /* Change this for different ratio than 16:9 */
left: 0;
// opacity: 0.7;
}
.wistia .play-button {
width: 90px;
height: 60px;
background-color: #333;
// box-shadow: 0 0 30px rgba( 0,0,0,0.6 );
z-index: 1;
// opacity: 0.8;
border-radius: 6px;
}
.wistia .play-button:before {
content: "";
border-style: solid;
border-width: 15px 0 15px 26.0px;
border-color: transparent transparent transparent #fff;
}
.wistia img,
.wistia .play-button {
cursor: pointer;
}
.wistia img,
.wistia iframe,
.wistia .play-button,
.wistia .play-button:before {
position: absolute;
}
.wistia .play-button,
.wistia .play-button:before {
top: 50%;
left: 50%;
transform: translate3d( -50%, -50%, 0 );
}
.wistia iframe {
height: 100%;
width: 100%;
top: 0;
left: 0;
}
<div class="wistia" data-embed="fousa0gqve" data-thumb="772ba38639a8dd752968933b95e3a7282f4d6a7b">
<div class="play-button"></div>
</div>