我正在尝试通过 Smart Slider 3 插件禁用服务器上托管的 MP4 背景短视频的自动播放功能,以便它们仅在鼠标悬停时播放。不幸的是,尽管在数百个 div 中尝试了多种 JavaScript 变体,但我没有成功。顺便说一句,所有视频均已静音。我什至尝试阻止网站上所有 MP4 视频的自动播放,但再次没有成功。感谢您的支持,祝您度过愉快的一天。我最后尝试的代码如下...
Url: sedaulgen.com/yeni-anasayfa
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('video.n2-ss-slide-background-video').forEach(video => {
// Videoyu yüklenir yüklenmez durdur
video.pause();
video.removeAttribute('autoplay');
video.muted = true; // Sesi kapat
// Videonun üzerine gelindiğinde başlat
video.addEventListener('mouseenter', () => {
video.play();
});
// Videodan ayrıldığında durdur
video.addEventListener('mouseleave', () => {
video.pause();
});
});
});
document.addEventListener('DOMContentLoaded', () => {
setInterval(() => {
document.querySelectorAll('video.n2-ss-slide-background-video').forEach(video => {
video.removeAttribute('autoplay');
});
}, 1000); // Her saniyede bir kontrol eder
});
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('video.n2-ss-slide-background-video').forEach(video => {
video.pause();
video.removeAttribute('autoplay');
video.muted = true; // Sesi kapat
video.addEventListener('mouseenter', () => {
video.play();
});
video.addEventListener('mouseleave', () => {
video.pause();
});
});
});
document.addEventListener('DOMContentLoaded', () => {
setInterval(() => {
document.querySelectorAll('video.n2-ss-slide-background-video').forEach(video => {
video.removeAttribute('autoplay');
});
}, 1000);
});
您需要在 URL 中添加一个额外参数来禁用自动播放:
&autoplay=0
您有 iframe 的代码,如下所示:
<iframe
class="elementor-video-iframe" allowfullscreen allow="clipboard-write"
title="vimeo Video Oynatıcı"
src="https://player.vimeo.com/video/888309521?color&autopause=0&loop=0&muted=0&title=1&portrait=1&byline=1#t="
>
</iframe>
尝试将
src
部分更改为嵌入中的如下所示:#t=
修复为 #t=0
以从零开始时间播放视频。)
https://player.vimeo.com/video/888309521?color&autoplay=0&autopause=0&loop=0&muted=0&title=1&portrait=1&byline=1#t=0