refactor(css): 添加 contain 属性优化布局性能
- 在多个组件样式中添加 contain: layout style 提升渲染性能 - 移除移动端浮动按钮的拖拽功能实现 - 简化 JavaScript 中的 FAB 元素初始化逻辑 - 清理未使用的拖拽相关事件监听器绑定代码
This commit is contained in:
@@ -322,6 +322,7 @@ body {
|
|||||||
/* 确保不继承任何可能影响文字的滤镜或动画 */
|
/* 确保不继承任何可能影响文字的滤镜或动画 */
|
||||||
filter: none;
|
filter: none;
|
||||||
animation: none;
|
animation: none;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 黑夜模式下个人卡片发光效果 */
|
/* 黑夜模式下个人卡片发光效果 */
|
||||||
@@ -701,6 +702,7 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -708,6 +710,7 @@ body {
|
|||||||
/* --- Interests --- */
|
/* --- Interests --- */
|
||||||
.area-interests {
|
.area-interests {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1563,6 +1566,7 @@ body {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
/* 创建独立的层叠上下文,防止动画影响子元素 */
|
/* 创建独立的层叠上下文,防止动画影响子元素 */
|
||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 增强版呼吸动画:多层光晕 + 色彩流动 */
|
/* 增强版呼吸动画:多层光晕 + 色彩流动 */
|
||||||
@@ -1982,6 +1986,7 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-header {
|
.card-header {
|
||||||
@@ -2048,6 +2053,7 @@ body {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
pointer-events: none; /* 禁用鼠标事件避免干扰 */
|
pointer-events: none; /* 禁用鼠标事件避免干扰 */
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 白天模式下为 tag-color 类增强可读性 */
|
/* 白天模式下为 tag-color 类增强可读性 */
|
||||||
@@ -2851,6 +2857,7 @@ body {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mobile Social */
|
/* Mobile Social */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
/* Base Artalk container styles */
|
/* Base Artalk container styles */
|
||||||
#artalk-container {
|
#artalk-container {
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
|
contain: layout style;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 确保评论区域适配白天/黑夜模式 */
|
/* 确保评论区域适配白天/黑夜模式 */
|
||||||
|
|||||||
69
js/about.js
69
js/about.js
@@ -962,8 +962,6 @@ class UIManager {
|
|||||||
const fMusic = document.getElementById('fab-music');
|
const fMusic = document.getElementById('fab-music');
|
||||||
if (!main || !menu || !fLang || !fTheme || !fMusic) return;
|
if (!main || !menu || !fLang || !fTheme || !fMusic) return;
|
||||||
|
|
||||||
// 添加拖拽功能
|
|
||||||
this.initDraggableFab();
|
|
||||||
|
|
||||||
const updateLabels = () => {
|
const updateLabels = () => {
|
||||||
// 使用requestAnimationFrame避免强制重排
|
// 使用requestAnimationFrame避免强制重排
|
||||||
@@ -1012,73 +1010,6 @@ class UIManager {
|
|||||||
requestAnimationFrame(updateLabels);
|
requestAnimationFrame(updateLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化拖拽功能
|
|
||||||
initDraggableFab() {
|
|
||||||
const fab = document.querySelector('.mobile-fab');
|
|
||||||
if (!fab) return;
|
|
||||||
|
|
||||||
let isDragging = false;
|
|
||||||
let initialX, initialY, currentX, currentY, xOffset = 0, yOffset = 0;
|
|
||||||
fab.style.willChange = 'transform';
|
|
||||||
|
|
||||||
// 拖拽相关方法
|
|
||||||
const setTranslate = (xPos, yPos, el) => {
|
|
||||||
el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const dragStart = (e) => {
|
|
||||||
if (e.type === 'touchstart') {
|
|
||||||
initialX = e.touches[0].clientX - xOffset;
|
|
||||||
initialY = e.touches[0].clientY - yOffset;
|
|
||||||
} else {
|
|
||||||
initialX = e.clientX - xOffset;
|
|
||||||
initialY = e.clientY - yOffset;
|
|
||||||
}
|
|
||||||
isDragging = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const dragEnd = () => {
|
|
||||||
initialX = currentX;
|
|
||||||
initialY = currentY;
|
|
||||||
isDragging = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const drag = (e) => {
|
|
||||||
if (isDragging) {
|
|
||||||
e.preventDefault();
|
|
||||||
if (e.type === 'touchmove') {
|
|
||||||
currentX = e.touches[0].clientX - initialX;
|
|
||||||
currentY = e.touches[0].clientY - initialY;
|
|
||||||
} else {
|
|
||||||
currentX = e.clientX - initialX;
|
|
||||||
currentY = e.clientY - initialY;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用requestAnimationFrame优化拖拽动画
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
const ww = window.innerWidth;
|
|
||||||
const wh = window.innerHeight;
|
|
||||||
const rect = fab.getBoundingClientRect();
|
|
||||||
const fw = rect.width;
|
|
||||||
const fh = rect.height;
|
|
||||||
currentX = Math.max(0, Math.min(currentX, ww - fw));
|
|
||||||
currentY = Math.max(0, Math.min(currentY, wh - fh));
|
|
||||||
|
|
||||||
xOffset = currentX;
|
|
||||||
yOffset = currentY;
|
|
||||||
setTranslate(currentX, currentY, fab);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 绑定事件
|
|
||||||
fab.addEventListener('touchstart', dragStart, { passive: false });
|
|
||||||
fab.addEventListener('touchend', dragEnd, { passive: false });
|
|
||||||
fab.addEventListener('touchmove', drag, { passive: false });
|
|
||||||
fab.addEventListener('mousedown', dragStart, { passive: false });
|
|
||||||
fab.addEventListener('mouseup', dragEnd, { passive: false });
|
|
||||||
fab.addEventListener('mousemove', drag, { passive: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
initAudio() {
|
initAudio() {
|
||||||
const el = document.getElementById('site-audio');
|
const el = document.getElementById('site-audio');
|
||||||
|
|||||||
Reference in New Issue
Block a user