refactor(script): 重构脚本加载和错误处理
- 添加 moments.js 新脚本文件,分离瞬间功能逻辑 - 为百度统计和 Google Analytics 添加错误处理 - 更新 main.js,移除瞬间功能相关代码
This commit is contained in:
36
js/moments.js
Normal file
36
js/moments.js
Normal file
@@ -0,0 +1,36 @@
|
||||
$(document).ready(function () {
|
||||
// 处理瞬间链接点击事件
|
||||
$('.moments-link').on('click', function (e) {
|
||||
e.preventDefault(); // 阻止默认跳转
|
||||
|
||||
// 获取链接地址
|
||||
var url = "https://moments.hehouhui.cn";
|
||||
console.log("当前用户UA-", navigator.userAgent)
|
||||
// 判断是否是移动端
|
||||
var isMobile = /iPhone|Android/i.test(navigator.userAgent);
|
||||
|
||||
if (isMobile) {
|
||||
// 移动端:直接跳转
|
||||
window.location.href = url;
|
||||
} else {
|
||||
// PC端:在模拟器中显示
|
||||
$('#moment-frame').attr('src', url);
|
||||
$('.iphone-simulator').show();
|
||||
$('.overlay').show();
|
||||
}
|
||||
});
|
||||
|
||||
// 关闭按钮点击事件
|
||||
$('.close-btn').on('click', function () {
|
||||
$('.iphone-simulator').hide();
|
||||
$('.overlay').hide();
|
||||
$('#moment-frame').attr('src', ''); // 清空iframe内容
|
||||
});
|
||||
|
||||
// 遮罩层点击事件
|
||||
$('.overlay').on('click', function () {
|
||||
$(this).hide();
|
||||
$('.iphone-simulator').hide();
|
||||
$('#moment-frame').attr('src', '');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user