$(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( '扫码关注广仁微信公众号
点击任意处关闭