Skip to content

Commit 7eeff48

Browse files
committed
feat: 调整悬浮图标样式
1 parent 6a722a5 commit 7eeff48

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

img/qrcode.jpg

8.5 KB
Loading
Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,50 @@ <h4>更多</h4>
801801
const iconContainer = document.getElementById('iconContainer');
802802
const icons = CONFIG.floatingIcons;
803803

804-
icons.forEach(icon => {
804+
icons.forEach((icon, index) => {
805805
const iconEl = document.createElement('div');
806806
iconEl.className = 'floating-icon';
807-
iconEl.style.left = icon.x + '%';
808-
iconEl.style.top = icon.y + '%';
807+
808+
// 围绕hero-right区域分布图标
809+
// 在右半边区域内随机分布,但避开中心的插图区域
810+
const rightAreaStart = 55; // 右半边开始位置
811+
const rightAreaWidth = 40; // 右半边可用宽度
812+
813+
// 根据原始配置调整到右半边区域
814+
let adjustedX = rightAreaStart + (icon.x / 100) * rightAreaWidth;
815+
816+
// 调整Y坐标,避免图标太靠近顶部
817+
// 将原来的0-100%映射到8-92%,给顶部留出少量空间
818+
let adjustedY = 8 + (icon.y / 100) * 84;
819+
820+
// 如果图标太靠近中心插图区域,向外推移
821+
const centerX = 75; // 插图大概在75%位置
822+
const centerY = 50; // 插图大概在50%高度位置
823+
const avoidRadius = 15; // 避开插图的半径
824+
825+
const distanceFromCenter = Math.sqrt(
826+
Math.pow(adjustedX - centerX, 2) +
827+
Math.pow(adjustedY - centerY, 2)
828+
);
829+
830+
if (distanceFromCenter < avoidRadius) {
831+
// 如果太靠近中心,向边缘推移
832+
if (adjustedX < centerX) {
833+
adjustedX = Math.max(rightAreaStart, adjustedX - 10);
834+
} else {
835+
adjustedX = Math.min(95, adjustedX + 10);
836+
}
837+
838+
// 垂直方向也进行调整
839+
if (adjustedY < centerY) {
840+
adjustedY = Math.max(8, adjustedY - 5);
841+
} else {
842+
adjustedY = Math.min(92, adjustedY + 5);
843+
}
844+
}
845+
846+
iconEl.style.left = adjustedX + '%';
847+
iconEl.style.top = adjustedY + '%';
809848
iconEl.style.animationDelay = icon.delay + 's';
810849
iconEl.innerHTML = `<img src="${icon.src}" alt="${icon.alt}">`;
811850
iconContainer.appendChild(iconEl);
@@ -826,10 +865,15 @@ <h4>更多</h4>
826865

827866
const floatingIcons = document.querySelectorAll('.floating-icon');
828867
floatingIcons.forEach((icon, index) => {
829-
const speed = (index % 3 + 1) * 15;
868+
const speed = (index % 3 + 1) * 10; // 减小移动幅度
830869
const x = currentX * speed;
831870
const y = currentY * speed;
832-
icon.style.transform = `translate(${x}px, ${y}px)`;
871+
872+
// 获取当前图标位置,确保不会移出右半边区域
873+
const currentLeft = parseFloat(icon.style.left);
874+
const newX = Math.max(-20, Math.min(20, x)); // 限制移动范围
875+
876+
icon.style.transform = `translate(${newX}px, ${y}px)`;
833877
});
834878

835879
requestAnimationFrame(animate);

0 commit comments

Comments
 (0)