$(document).ready(function () { // 联系卡片点击效果 $(".contact-card").on("click", function () { const $this = $(this); const cardValue = $this.find(".card-value").text(); // 根据卡片类型执行不同操作 if (cardValue.includes("@")) { // 邮箱卡片 - 打开邮件客户端 window.location.href = "mailto:" + cardValue; } else if (cardValue.match(/\d{3}-\d{8}/)) { // 电话卡片 - 拨打电话 window.location.href = "tel:" + cardValue.replace(/-/g, ""); } else { // 地址卡片 - 复制地址 copyToClipboard(cardValue); showToast("地址已复制到剪贴板"); } }); // 复制到剪贴板函数 function copyToClipboard(text) { if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text).then( function () { console.log("复制成功"); }, function (err) { console.error("复制失败", err); fallbackCopyToClipboard(text); } ); } else { fallbackCopyToClipboard(text); } } // 兼容旧浏览器的复制方法 function fallbackCopyToClipboard(text) { const textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; textArea.style.top = "0"; textArea.style.left = "0"; textArea.style.width = "2em"; textArea.style.height = "2em"; textArea.style.padding = "0"; textArea.style.border = "none"; textArea.style.outline = "none"; textArea.style.boxShadow = "none"; textArea.style.background = "transparent"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { const successful = document.execCommand("copy"); if (successful) { console.log("复制成功"); } } catch (err) { console.error("复制失败", err); } document.body.removeChild(textArea); } // 显示提示信息 function showToast(message) { // 检查是否已有提示框 if ($(".toast-message").length > 0) { $(".toast-message").remove(); } const toast = $('
').text(message); $("body").append(toast); // 添加样式 toast.css({ position: "fixed", top: "50%", left: "50%", transform: "translate(-50%, -50%)", background: "rgba(0, 0, 0, 0.8)", color: "#ffffff", padding: "16px 32px", borderRadius: "8px", fontSize: "16px", zIndex: 10000, opacity: 0, transition: "opacity 0.3s ease", }); // 显示提示 setTimeout(function () { toast.css("opacity", 1); }, 10); // 2秒后隐藏并移除 setTimeout(function () { toast.css("opacity", 0); setTimeout(function () { toast.remove(); }, 300); }, 2000); } // 地图加载状态处理 const mapIframe = $(".map-container iframe"); if (mapIframe.length > 0) { mapIframe.on("load", function () { console.log("地图加载完成"); }); mapIframe.on("error", function () { console.error("地图加载失败"); $(".map-container").html( '
地图加载失败,请稍后重试
' ); }); } // 添加卡片悬停音效(可选) let isHoverSoundEnabled = false; // 默认关闭,避免打扰用户 if (isHoverSoundEnabled) { $(".contact-card").hover( function () { // 悬停时的效果 $(this).find(".card-icon").css("transform", "scale(1.1) rotate(5deg)"); }, function () { // 离开时恢复 $(this).find(".card-icon").css("transform", "scale(1) rotate(0deg)"); } ); } // 滚动动画增强 function animateOnScroll() { $(".contact-card, .qr-code-box").each(function () { const elementTop = $(this).offset().top; const elementBottom = elementTop + $(this).outerHeight(); const viewportTop = $(window).scrollTop(); const viewportBottom = viewportTop + $(window).height(); if (elementBottom > viewportTop && elementTop < viewportBottom - 100) { $(this).addClass("animated"); } }); } $(window).on("scroll", animateOnScroll); animateOnScroll(); // 初始检查 // 二维码放大查看功能 $(".qr-code-box").on("click", function () { const imgSrc = $(this).find("img").attr("src"); // 创建弹窗 const modal = $(`

扫码关注广仁微信公众号

点击任意处关闭

`); $("body").append(modal); // 点击关闭 modal.on("click", function () { modal.fadeOut(300, function () { modal.remove(); }); }); // 防止图片区域点击事件冒泡 modal.find("div").on("click", function (e) { e.stopPropagation(); }); }); // 标签菜单平滑滚动 $(".tab-menu-item").on("click", function (e) { const href = $(this).attr("href"); if (href.startsWith("#")) { e.preventDefault(); const target = $(href); if (target.length) { $("html, body").animate( { scrollTop: target.offset().top - 100, }, 600 ); } } }); // 响应式检测 function checkResponsive() { const width = $(window).width(); if (width <= 768) { // 移动端:调整地图高度 $(".map-container").css("height", "350px"); } else if (width <= 992) { // 平板端 $(".map-container").css("height", "400px"); } else { // 桌面端 $(".map-container").css("height", "450px"); } } $(window).on("resize", checkResponsive); checkResponsive(); // 页面加载完成后的初始化 console.log("服务中心页面初始化完成"); // 添加页面访问统计(如果需要) if (typeof gtag !== "undefined") { gtag("event", "page_view", { page_title: "服务中心 - 客服服务", page_location: window.location.href, page_path: window.location.pathname, }); } }); // 页面卸载前的清理 $(window).on("beforeunload", function () { // 清理定时器等资源 console.log("页面即将卸载"); });