1623
This commit is contained in:
1 parent
310be913ef
commit
fe8c99a53e
8 files changed
+367
-157
No files matched your search
@@ -35,8 +35,45 @@
|
||||
content.querySelectorAll('.post-video, .link-card').forEach(function(el) {
|
||||
if (!el.hasAttribute('uk-scrollspy')) el.setAttribute('uk-scrollspy', 'cls: uk-animation-slide-bottom-small; delay: 100');
|
||||
});
|
||||
// 初始化视频播放器
|
||||
initVideoPlayers();
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', initPostScrollspy);
|
||||
|
||||
// 视频 PJAX 适配
|
||||
function initVideoPlayers() {
|
||||
document.querySelectorAll('.post-content video, .post-video-wrapper video').forEach(function(video) {
|
||||
// 暗黑模式下视频控件适配
|
||||
if (document.documentElement.dataset.theme === 'dark') {
|
||||
video.style.filter = 'brightness(0.95)';
|
||||
} else {
|
||||
video.style.filter = '';
|
||||
}
|
||||
// 确保不自动播放
|
||||
video.removeAttribute('autoplay');
|
||||
video.pause();
|
||||
});
|
||||
// 嵌入视频(B站/YouTube)在 PJAX 后重新加载
|
||||
document.querySelectorAll('.video-embed iframe').forEach(function(iframe) {
|
||||
var src = iframe.src;
|
||||
if (src) {
|
||||
iframe.src = src; // 触发重新加载
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// PJAX 导航前暂停所有视频
|
||||
document.addEventListener('pjax:send', function() {
|
||||
document.querySelectorAll('video').forEach(function(video) {
|
||||
video.pause();
|
||||
video.removeAttribute('autoplay');
|
||||
});
|
||||
});
|
||||
|
||||
// PJAX 加载完成后重新初始化
|
||||
document.addEventListener('pjax:complete', function() {
|
||||
setTimeout(initPostScrollspy, 100);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user