refactor(index): 重构瞬间功能并优化页面结构
- 移除 iPhone 模拟器,改为直接使用 iframe 嵌入瞬间页面 - 更新瞬间链接为实际 URL,取消 javascript:void(0)- 调整 iframe 容器样式,设置初始隐藏状态- 重构 moments.js,简化代码结构,优化动画效果 - 更新 CSS 链接为相对路径,提高性能
This commit is contained in:
136
css/style.css
136
css/style.css
@@ -10111,144 +10111,26 @@ j {
|
||||
}
|
||||
|
||||
|
||||
/* 模拟iPhone 16容器样式 */
|
||||
.iphone-simulator {
|
||||
/* 新增iframe容器样式 */
|
||||
#moments-container {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
right: 10px;
|
||||
transform: translate(-50%, -50%) scale(1);
|
||||
width: 395px; /* iPhone 16 Pro 宽度 */
|
||||
height: 830px; /* iPhone 16 Pro 高度 */
|
||||
max-width: 45vw; /* 自适应最大宽度为视口宽度的30% */
|
||||
max-height: 90vh; /* 自适应最大高度为视口高度的90% */
|
||||
aspect-ratio: 395 / 830; /* 保持 iPhone 16 Pro 比例 */
|
||||
border-radius: 47px; /* 真机圆角 */
|
||||
box-shadow: 0 0 0 12px #1a1a1a, /* 边框模拟 */
|
||||
0 0 0 14px #000, /* 外阴影 */
|
||||
0 40px 80px rgba(0,0,0,0.4); /* 真实阴影 */
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
z-index: 9999;
|
||||
}
|
||||
/* 模拟灵动岛 */
|
||||
.dynamic-island {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 126px;
|
||||
height: 37px;
|
||||
background: #000;
|
||||
border-radius: 20px;
|
||||
z-index: 10001;
|
||||
transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
|
||||
}
|
||||
|
||||
.dynamic-island.expand {
|
||||
width: 200px;
|
||||
height: 60px;
|
||||
border-radius: 30px;
|
||||
}
|
||||
|
||||
.dynamic-island .content {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.dynamic-island.expand .content {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 左上角返回按钮(带箭头图标) */
|
||||
.back-btn {
|
||||
position: absolute;
|
||||
top: 15px;
|
||||
left: 20px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: rgba(255,255,255,0.1);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
z-index: 10002;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.back-btn:hover {
|
||||
background: rgba(255,255,255,0.2);
|
||||
}
|
||||
.back-btn::before {
|
||||
content: '←';
|
||||
color: #258fb8;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
/* 内部浏览器视图容器 */
|
||||
.browser-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding-top: 50px; /* 避让灵动岛 */
|
||||
transform: translate(-50%, -50%);
|
||||
width: 80%;
|
||||
max-width: 800px;
|
||||
background-color: #fff;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
/* 移动端隐藏 */
|
||||
@media screen and (max-width: 768px) {
|
||||
.iphone-simulator, .overlay {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* CSS(骨架屏 + 淡入动画)
|
||||
* 点击链接 → 显示模拟器 → 动态加载网页 → 加载完成前显示骨架屏 → 加载完成后淡入网页
|
||||
*/
|
||||
.iphone-simulator .browser-view iframe {
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
||||
z-index: 9999;
|
||||
opacity: 0;
|
||||
transition: opacity 0.5s ease;
|
||||
}
|
||||
|
||||
.iphone-simulator .browser-view.loaded iframe {
|
||||
#moments-container.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.skeleton {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: shimmer 1.5s infinite;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { background-position: -200% 0; }
|
||||
100% { background-position: 200% 0; }
|
||||
}
|
||||
|
||||
/* MacBook风格的关闭按钮 */
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 25px;
|
||||
right: 20px;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
background: #ff5f56;
|
||||
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
z-index: 10000;
|
||||
}
|
||||
|
||||
/* 遮罩层 */
|
||||
.overlay {
|
||||
|
||||
21
index.html
21
index.html
@@ -13,7 +13,7 @@
|
||||
<meta name="keywords" content="Honesty,HeHouHui,HeHui,明厚">
|
||||
<meta name="author" content="HeHouHui">
|
||||
<title>Honesty的主页</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdmirror.com/gh/listener-He/Home/css/style.css?version=2">
|
||||
<link rel="stylesheet" type="text/css" href="/css/style.css?version=2">
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdmirror.com/gh/listener-He/Home/css/iconfont.css">
|
||||
<link rel="apple-touch-icon" href="https://blog-file.hehouhui.cn/bj/logo.png">
|
||||
<link rel="icon" href="https://cdn.jsdmirror.com/gh/listener-He/Home/favicon.ico?version=1">
|
||||
@@ -121,7 +121,8 @@
|
||||
<a href="https://nav.hehouhui.cn/"><span>导航</span><i></i></a>
|
||||
</li>
|
||||
<li class="navigation__item">
|
||||
<a href="javascript:void(0)" class="moments-link"><span>瞬间</span><i></i></a>
|
||||
<!-- javascript:void(0) -->
|
||||
<a href="https://moments.hehouhui.cn" class="moments-link"><span>瞬间</span><i></i></a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
@@ -194,17 +195,9 @@
|
||||
</p>
|
||||
</div>
|
||||
</header>
|
||||
<!-- 模拟iPhone 16容器 -->
|
||||
<div class="iphone-simulator" style="display: none">
|
||||
<div class="dynamic-island">
|
||||
<p class="content"></p>
|
||||
</div>
|
||||
<div class="back-btn"></div>
|
||||
<div class="browser-view">
|
||||
<div class="close-btn"></div>
|
||||
<div class="skeleton"></div>
|
||||
<iframe id="moment-frame" width="100%" height="100%" frameborder="0"></iframe>
|
||||
</div>
|
||||
<!-- iframe容器 -->
|
||||
<div id="moments-container" style="display: none;">
|
||||
<iframe id="moment-frame" src="" width="100%" height="500px" frameborder="0"></iframe>
|
||||
</div>
|
||||
|
||||
<!-- 遮罩层 -->
|
||||
@@ -215,7 +208,7 @@
|
||||
<script type="text/javascript" src="https://cdn.jsdmirror.com/gh/listener-He/Home/js/fetch.min.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.jsdmirror.com/gh/listener-He/Home/js/main.js?version=2"></script>
|
||||
<script type="text/javascript" src="https://cdn.jsdmirror.com/gh/listener-He/Home/js/bj.js"></script>
|
||||
<script type="text/javascript" src="https://cdn.jsdmirror.com/gh/listener-He/Home/js/moments.js"></script>
|
||||
<!--<script type="text/javascript" src="https://cdn.jsdmirror.com/gh/listener-He/Home/js/moments.js"></script>-->
|
||||
<script async src="https://analyse.hehouhui.cn/tracker.js" data-ackee-server="https://analyse.hehouhui.cn"
|
||||
data-ackee-domain-id="7887135f-a413-46e2-a98c-52d4f18d9973"></script>
|
||||
<script>
|
||||
|
||||
@@ -1,47 +1,33 @@
|
||||
$(document).ready(function () {
|
||||
const iframe = document.getElementById('moment-frame');
|
||||
function animateDynamicIsland(text = '正在加载...') {
|
||||
const island = document.querySelector('.dynamic-island');
|
||||
const content = island.querySelector('.content');
|
||||
const momentsContainer = document.getElementById('moments-container');
|
||||
|
||||
content.textContent = text;
|
||||
island.classList.add('expand');
|
||||
|
||||
setTimeout(() => {
|
||||
island.classList.remove('expand');
|
||||
}, (iframe.src == null || iframe.src === '') ? 2000 : 250); // 2秒后收缩
|
||||
function animateIframe() {
|
||||
momentsContainer.style.display = 'block';
|
||||
momentsContainer.classList.add('visible');
|
||||
}
|
||||
|
||||
function openSimulator(url) {
|
||||
const sim = document.querySelector('.iphone-simulator');
|
||||
const overlay = document.querySelector('.overlay');
|
||||
const skeleton = document.querySelector('.skeleton');
|
||||
sim.style.display = 'block';
|
||||
overlay.style.display = 'block';
|
||||
function openMoments(url) {
|
||||
if (iframe.src == null || iframe.src === '' || iframe.src !== url) {
|
||||
const browserView = document.querySelector('.browser-view');
|
||||
iframe.src = url;
|
||||
|
||||
iframe.onload = () => {
|
||||
setTimeout(() => {
|
||||
skeleton.style.display = 'none';
|
||||
browserView.classList.add('loaded');
|
||||
animateIframe();
|
||||
}, 300); // 延迟更自然
|
||||
};
|
||||
} else {
|
||||
skeleton.style.display = 'none';
|
||||
animateIframe();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 处理瞬间链接点击事件
|
||||
$('.moments-link').on('click', function (e) {
|
||||
e.preventDefault(); // 阻止默认跳转
|
||||
|
||||
// 获取链接地址
|
||||
const url = "https://moments.hehouhui.cn";
|
||||
|
||||
// 判断是否是移动端
|
||||
const isMobile = /iPhone|Android/i.test(navigator.userAgent);
|
||||
|
||||
@@ -49,35 +35,24 @@ $(document).ready(function () {
|
||||
// 移动端:直接跳转
|
||||
window.location.href = url;
|
||||
} else {
|
||||
animateDynamicIsland('正在加载瞬间...');
|
||||
// PC端:在模拟器中显示
|
||||
openSimulator(url);
|
||||
// PC端:在iframe中显示
|
||||
openMoments(url);
|
||||
}
|
||||
});
|
||||
|
||||
// 关闭按钮点击事件
|
||||
$('.close-btn').on('click', function () {
|
||||
$('.iphone-simulator').hide();
|
||||
$('.overlay').hide();
|
||||
$('.iphone-simulator').removeClass('visible');
|
||||
momentsContainer.classList.remove('visible');
|
||||
setTimeout(() => {
|
||||
momentsContainer.style.display = 'none';
|
||||
}, 500); // 等待动画结束后隐藏
|
||||
});
|
||||
|
||||
// 遮罩层点击事件 点击空白处关闭模拟器
|
||||
$('.overlay').on('click', function () {
|
||||
$(this).hide();
|
||||
$('.iphone-simulator').hide();
|
||||
$('.iphone-simulator').removeClass('visible');
|
||||
});
|
||||
|
||||
document.querySelector('.back-btn').addEventListener('click', () => {
|
||||
try {
|
||||
// 安全地尝试让 iframe 内部回退
|
||||
if (iframe.contentWindow && iframe.contentWindow.history.length > 1) {
|
||||
iframe.contentWindow.history.back();
|
||||
}
|
||||
} catch (e) {
|
||||
// 跨域或权限问题
|
||||
console.error('无法回退:', e);
|
||||
}
|
||||
momentsContainer.classList.remove('visible');
|
||||
setTimeout(() => {
|
||||
momentsContainer.style.display = 'none';
|
||||
}, 500); // 等待动画结束后隐藏
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user