perf(moments): 优化动态岛和 iframe 加载逻辑
- 添加 iframe 加载判断,动态调整动态岛收缩时间 - 优化 iframe 源的加载逻辑,减少重复加载 - 移除冗余的 iframe 源清空操作 - 修复后退按钮点击事件
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
const iframe = document.getElementById('moment-frame');
|
||||||
function animateDynamicIsland(text = '正在加载...') {
|
function animateDynamicIsland(text = '正在加载...') {
|
||||||
const island = document.querySelector('.dynamic-island');
|
const island = document.querySelector('.dynamic-island');
|
||||||
const content = island.querySelector('.content');
|
const content = island.querySelector('.content');
|
||||||
@@ -8,18 +9,17 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
island.classList.remove('expand');
|
island.classList.remove('expand');
|
||||||
}, 2000); // 2秒后收缩
|
}, (iframe.src == null || iframe.src === '') ? 2000 : 250); // 2秒后收缩
|
||||||
}
|
}
|
||||||
|
|
||||||
function openSimulator(url) {
|
function openSimulator(url) {
|
||||||
const sim = document.querySelector('.iphone-simulator');
|
const sim = document.querySelector('.iphone-simulator');
|
||||||
const iframe = document.getElementById('moment-frame');
|
const overlay = document.querySelector('.overlay');
|
||||||
const skeleton = document.querySelector('.skeleton');
|
const skeleton = document.querySelector('.skeleton');
|
||||||
const browserView = document.querySelector('.browser-view');
|
|
||||||
|
|
||||||
sim.style.display = 'block';
|
sim.style.display = 'block';
|
||||||
document.querySelector('.overlay').style.display = 'block';
|
overlay.style.display = 'block';
|
||||||
|
if (iframe.src == null || iframe.src === '' || iframe.src !== url) {
|
||||||
|
const browserView = document.querySelector('.browser-view');
|
||||||
iframe.src = url;
|
iframe.src = url;
|
||||||
|
|
||||||
iframe.onload = () => {
|
iframe.onload = () => {
|
||||||
@@ -28,16 +28,22 @@ $(document).ready(function () {
|
|||||||
browserView.classList.add('loaded');
|
browserView.classList.add('loaded');
|
||||||
}, 300); // 延迟更自然
|
}, 300); // 延迟更自然
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
skeleton.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 处理瞬间链接点击事件
|
// 处理瞬间链接点击事件
|
||||||
$('.moments-link').on('click', function (e) {
|
$('.moments-link').on('click', function (e) {
|
||||||
e.preventDefault(); // 阻止默认跳转
|
e.preventDefault(); // 阻止默认跳转
|
||||||
|
|
||||||
// 获取链接地址
|
// 获取链接地址
|
||||||
var url = "https://moments.hehouhui.cn";
|
const url = "https://moments.hehouhui.cn";
|
||||||
// 判断是否是移动端
|
// 判断是否是移动端
|
||||||
var isMobile = /iPhone|Android/i.test(navigator.userAgent);
|
const isMobile = /iPhone|Android/i.test(navigator.userAgent);
|
||||||
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
// 移动端:直接跳转
|
// 移动端:直接跳转
|
||||||
@@ -54,7 +60,6 @@ $(document).ready(function () {
|
|||||||
$('.iphone-simulator').hide();
|
$('.iphone-simulator').hide();
|
||||||
$('.overlay').hide();
|
$('.overlay').hide();
|
||||||
$('.iphone-simulator').removeClass('visible');
|
$('.iphone-simulator').removeClass('visible');
|
||||||
$('#moment-frame').attr('src', ''); // 清空iframe内容
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 遮罩层点击事件 点击空白处关闭模拟器
|
// 遮罩层点击事件 点击空白处关闭模拟器
|
||||||
@@ -62,10 +67,8 @@ $(document).ready(function () {
|
|||||||
$(this).hide();
|
$(this).hide();
|
||||||
$('.iphone-simulator').hide();
|
$('.iphone-simulator').hide();
|
||||||
$('.iphone-simulator').removeClass('visible');
|
$('.iphone-simulator').removeClass('visible');
|
||||||
$('#moment-frame').attr('src', '');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const iframe = document.getElementById('moment-frame');
|
|
||||||
document.querySelector('.back-btn').addEventListener('click', () => {
|
document.querySelector('.back-btn').addEventListener('click', () => {
|
||||||
try {
|
try {
|
||||||
// 安全地尝试让 iframe 内部回退
|
// 安全地尝试让 iframe 内部回退
|
||||||
|
|||||||
Reference in New Issue
Block a user