侧边栏随机视频
效果展示
不想截图了,自己看本站侧边栏第一步
在 source👉_data 下面新建 widget.yml
第二步
把下面内容直接张贴进去就ok了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| bottom: - class_name: video-player-widget id_name: video-player-widget name: 养会儿眼睛 icon: fas fa-video order: 0 html: | <div id="video-player-widget" style="width: 265px; height: 500px; border-radius: 20px; overflow: hidden; position: relative; background-color: #000; box-shadow: 0 8px 20px rgba(0,0,0,0.8);"> <!-- 视频播放器 --> <video id="player" autoplay style="width: 100%; height: 100%; object-fit: cover;"></video> <!-- 音量滑块 --> <div class="volume-control" style="position: absolute; bottom: 30px; left: 20px; display: flex; align-items: center; opacity: 0.7;"> <input id="volumeSlider" type="range" min="0" max="1" step="0.1" value="0.5" style="width: 80px;"> </div> <!-- 下一个按钮 --> <button id="nextButton" style="position: absolute; bottom: 30px; right: 20px; background-color: rgba(255, 255, 255, 0.85); border: none; color: #000; font-size: 12px; font-weight: bold; padding: 6px 12px; border-radius: 50px; cursor: pointer; box-shadow: 0 4px 10px rgba(255,255,255,0.3);">下一个</button> </div>
<!-- 视频播放器逻辑 --> <script> const player = document.getElementById('player'); const nextButton = document.getElementById('nextButton'); const volumeSlider = document.getElementById('volumeSlider'); const videoAPI = "https://api.kuleu.com/api/MP4_xiaojiejie?type=json";
async function loadNextVideo() { try { const response = await fetch(videoAPI); const data = await response.json(); if (data.code === 200 && data.mp4_video) { player.src = data.mp4_video; player.play(); } else { console.error("视频加载失败:", data.msg); } } catch (error) { console.error("请求出错:", error); } }
// 初始化 loadNextVideo(); player.addEventListener('ended', loadNextVideo); nextButton.addEventListener('click', loadNextVideo); volumeSlider.addEventListener('input', (e) => player.volume = e.target.value); player.volume = volumeSlider.value; </script>
|
里面的width: 265px; height: 500px;
一个是播放器的宽,一个是他的高,看着不爽自己改改,const videoAPI = "https://api.kuleu.com/api/MP4_xiaojiejie?type=json";
这里是随机视频的api
粘贴的位置不一样显示的部位也不一样,具体的看top: 创建的 widget 会出现在非 sticky 区域(即所有页面都会显示),bottom: 创建的 widget 会出现在 sticky 区域(除了文章页都会显示)
[!NOTE]
如果遇到视频不加载或者无法播放直接刷新一下就好了