fix: 修复移动端深色模式和毛玻璃效果兼容性问题
- 添加 backdrop-filter 支持检测,不支持时使用降级方案 - 添加移动端设备检测类 is-mobile-device - 监听深色模式切换,强制刷新样式解决颜色不更新问题 - 为移动端添加强制文字颜色修复 - 简化代码结构,移除冗余检测逻辑
This commit is contained in:
89
header.php
89
header.php
@@ -289,40 +289,81 @@
|
|||||||
|
|
||||||
<?php wp_head(); ?>
|
<?php wp_head(); ?>
|
||||||
|
|
||||||
<!-- 移动端资源加载修复 - 确保 CSS 完全应用 -->
|
<!-- 移动端兼容性修复 -->
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
// 检测移动端并强制重新计算样式
|
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||||
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
|
var html = document.documentElement;
|
||||||
// 确保 CSS 已加载
|
|
||||||
var checkCSS = function() {
|
|
||||||
var testEl = document.createElement('div');
|
|
||||||
testEl.className = 'container';
|
|
||||||
testEl.style.cssText = 'position:absolute;visibility:hidden;';
|
|
||||||
document.body.appendChild(testEl);
|
|
||||||
var computed = window.getComputedStyle(testEl);
|
|
||||||
var isLoaded = computed.width !== 'auto' && computed.width !== '';
|
|
||||||
document.body.removeChild(testEl);
|
|
||||||
return isLoaded;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 如果 CSS 未完全加载,强制重新加载
|
// 检测 backdrop-filter 支持
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
var supportsBackdrop = CSS.supports && (
|
||||||
if (!checkCSS()) {
|
CSS.supports('backdrop-filter', 'blur(1px)') ||
|
||||||
// 触发重排以应用样式
|
CSS.supports('-webkit-backdrop-filter', 'blur(1px)')
|
||||||
document.body.style.display = 'none';
|
);
|
||||||
document.body.offsetHeight; // 强制重排
|
|
||||||
document.body.style.display = '';
|
if (!supportsBackdrop) {
|
||||||
}
|
html.classList.add('no-backdrop-filter');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
html.classList.add('is-mobile-device');
|
||||||
|
|
||||||
|
// 监听深色模式切换,强制刷新样式
|
||||||
|
var observer = new MutationObserver(function(mutations) {
|
||||||
|
mutations.forEach(function(mutation) {
|
||||||
|
if (mutation.attributeName === 'class') {
|
||||||
|
// 强制重新计算所有样式
|
||||||
|
document.body.style.display = 'none';
|
||||||
|
void document.body.offsetHeight;
|
||||||
|
document.body.style.display = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
observer.observe(html, { attributes: true, attributeFilter: ['class'] });
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// 用户角色检测 - 传递给前端JavaScript
|
// 用户角色检测
|
||||||
window.argonUserRole = '<?php echo current_user_can('administrator') ? 'administrator' : (is_user_logged_in() ? 'user' : 'guest'); ?>';
|
window.argonUserRole = '<?php echo current_user_can('administrator') ? 'administrator' : (is_user_logged_in() ? 'user' : 'guest'); ?>';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Argon 修复补丁 - 必须在 wp_head() 之后立即执行 -->
|
<!-- 移动端降级样式 -->
|
||||||
|
<style>
|
||||||
|
/* 不支持 backdrop-filter 时的降级方案 */
|
||||||
|
html.no-backdrop-filter .card.bg-white,
|
||||||
|
html.no-backdrop-filter article.post.card,
|
||||||
|
html.no-backdrop-filter #comments.card,
|
||||||
|
html.no-backdrop-filter #post_comment.card {
|
||||||
|
background-color: rgba(255, 255, 255, 0.95) !important;
|
||||||
|
}
|
||||||
|
html.no-backdrop-filter.darkmode .card.bg-white,
|
||||||
|
html.no-backdrop-filter.darkmode article.post.card,
|
||||||
|
html.no-backdrop-filter.darkmode #comments.card,
|
||||||
|
html.no-backdrop-filter.darkmode #post_comment.card {
|
||||||
|
background-color: rgba(50, 50, 50, 0.95) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 移动端深色模式文字颜色强制修复 */
|
||||||
|
html.is-mobile-device.darkmode body,
|
||||||
|
html.is-mobile-device.darkmode .post-content,
|
||||||
|
html.is-mobile-device.darkmode .card-body,
|
||||||
|
html.is-mobile-device.darkmode p,
|
||||||
|
html.is-mobile-device.darkmode span,
|
||||||
|
html.is-mobile-device.darkmode li {
|
||||||
|
color: #eee !important;
|
||||||
|
}
|
||||||
|
html.is-mobile-device:not(.darkmode) body,
|
||||||
|
html.is-mobile-device:not(.darkmode) .post-content,
|
||||||
|
html.is-mobile-device:not(.darkmode) .card-body,
|
||||||
|
html.is-mobile-device:not(.darkmode) p,
|
||||||
|
html.is-mobile-device:not(.darkmode) span:not(.badge),
|
||||||
|
html.is-mobile-device:not(.darkmode) li {
|
||||||
|
color: #525f7f !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<!-- Argon 修复补丁 -->
|
||||||
<script src="<?php echo get_template_directory_uri(); ?>/assets/js/argon.min.js?ver=<?php echo $GLOBALS['theme_version']; ?>"></script>
|
<script src="<?php echo get_template_directory_uri(); ?>/assets/js/argon.min.js?ver=<?php echo $GLOBALS['theme_version']; ?>"></script>
|
||||||
|
|
||||||
<?php $GLOBALS['wp_path'] = get_option('argon_wp_path') == '' ? '/' : get_option('argon_wp_path'); ?>
|
<?php $GLOBALS['wp_path'] = get_option('argon_wp_path') == '' ? '/' : get_option('argon_wp_path'); ?>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
"commit": "5ecbacb"
|
"commit": "14edc70"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user