收起左侧

将flatnas背景改为视频壁纸

0
回复
29
查看
[ 复制链接 ]

0

主题

41

回帖

0

牛值

江湖小虾

1.将视频上传至nas

image.png

2.打开flatnas设置

image.png

3.粘贴代码到自定义js中

image.png

视频名称修改为你自己的,视频尽量不要超过10M,否则会卡顿

image.png

JS

const bgElement = document.querySelector('.bg-no-repeat');
bgElement.style.backgroundImage = 'none';
const bgVideo = document.createElement('video');
bgVideo.src = '/backgrounds/123.mp4';  
bgVideo.loop = true;  
bgVideo.muted = true;  
bgVideo.autoplay = true;  
bgVideo.style.cssText = `
  position: absolute;  
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;  
  z-index: -1;  
`;
bgElement.style.setProperty('position', 'absolute', 'important');
bgElement.style.setProperty('filter', 'blur(0px)', 'important');
bgElement.style.overflow = 'hidden';  
bgElement.appendChild(bgVideo);
document.addEventListener('visibilitychange', () => {
  // 判断:页面从不可见变为可见(document.hidden 为 false)
  if (!document.hidden) {
    // 关键:调用 video.play() 主动恢复视频播放
    // 注意:play() 返回 Promise,可捕获潜在播放错误(可选)
    bgVideo.play().catch(err => {
      console.warn('视频恢复播放失败:', err);
    });
  }
});
收藏
送赞 1
分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则