(function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { let clientWidth1 = docEl.clientWidth; // alert(clientWidth1) if (!clientWidth1) return; if (clientWidth1 <= 1024) { docEl.style.fontSize = 100 * (clientWidth1 / 750) + 'px'; } else if (clientWidth1 > 1024 && clientWidth1 <= 1920) { docEl.style.fontSize = 100 * (clientWidth1 / 1920) + 'px'; } else if (clientWidth1 > 1920) { docEl.style.fontSize = 100 + 'px'; } }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window); $(document).ready(function () { // 顶部导航显示隐藏 var p = 0, t = 0; $(window).scroll(function () { p = $(this).scrollTop(); if (p > 200) { $('.header-wrap').addClass('headerBg') } else { $('.header-wrap').removeClass('headerBg') } if (t < p) { //下滚 // console.log('向下') if (p > 120) { $('.header-wrap').addClass('headerHide') } } else { //上滚 // console.log('向上'); $('.header-wrap').removeClass('headerHide') } setTimeout(function () { t = p; }, 0) }) }) //判断移动端设备 function ismobile() { if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i) ) return 1; return 0; } var clientWidth = document.documentElement.clientWidth; setTimeout(() => { if (clientWidth <= 768 || ismobile() == 1) { var metaEl = document.querySelector('meta[name="viewport"]'); var scale = clientWidth / 1920; // metaEl.setAttribute('content', 'width=device-width, initial-scale=' + .2); console.log('设置移动端缩放比例', metaEl); if (ismobile() == 1) { // loadMobileCss(); } } }, 1500) if (localStorage.getItem('testPhone') == 'testPhone') { if (ismobile() == 1) { alert('屏幕宽度' + clientWidth) setTimeout(() => { loadVconsole(); }, 3000) } } // 金沙威尼斯欢乐娱人城项目 if (ismobile()) { console.log("此时是移动端") } else { // 鼠标下滑,隐藏导航 var windowTop = 0; //初始话可视区域距离页面顶端的距离 $(window).scroll(function() { var scrolls = $(this).scrollTop(); //获取当前可视区域距离页面顶端的距离 if(scrolls >= 200){ //当scrolls>windowTop时,表示页面在向下滑动 //需要执行隐藏导航的操作 $(".main_header").slideUp(200) windowTop=scrolls; }else if (scrolls <= 200) { //需要执行显示导航动画操作 $(".main_header").slideDown(200) windowTop=scrolls; return } }); } $(function() { //导航 $(".header-menu-phone").click(function() { $('body').addClass('lock'); console.log("展示侧边栏"); $(".side-container").addClass("shown"); $(".side-modal").show(); init_show_nav(); }); //关闭导航 $(".side-close").click(function() { console.log("隐藏侧边栏"); $(".side-container").removeClass("shown"); $(".side-modal").hide(); $("body").removeClass('lock'); }); //导航初始化 function init_show_nav() { $(".side-nav-list-main").show(); $(".side-nav-list-sub").hide(); } //点击导航 // 注意有的导航有子项目 //主导航 $(".side-nav-list-main .nav-item-inner").click(function() { console.log("主导航操作"); var name = $(this).attr("data-name"); console.log("点击导航", name); var urlArr = ["首页", "联系我们"]; //可直接跳转的链接url var urlMap = { 首页: window.location.origin, 联系我们: "/lianxi/index.html", }; if (urlArr.includes(name)) { var url = urlMap[name]; window.location.href = url; } else { $(".side-nav-list-main").hide(); $('.side-nav-list-sub[data-name="' + name + '"]').show(); } }); //移动端 导航返回 $(".side-nav-list-sub .nav-item-inner-back").click(function() { console.log("返回操作"); $(".side-nav-list-main").show(); $(".side-nav-list-sub").hide(); }); //移动端 产品中心导航展开 $(".side-nav-list-sub .nav-item-inner-product").click(function() { console.log("/收起展开产品导航"); // $('.side-nav-list-main').show(); // $('.side-nav-list-sub').hide(); $(this).next().toggle(); $(this).find(".arrow-right").toggle(); $(this).find(".arrow-down").toggle(); }); //移动端展示搜索框 var isShowSearch = false; $(".header-search-phone").click(function() { console.log("搜索内容"); if (!isShowSearch) { $(".header-logo-box-phone").hide(); $(".header-search-box-phone").show(); } else { $(".header-logo-box-phone").show(); $(".header-search-box-phone").hide(); } isShowSearch = !isShowSearch; }); //移动端搜索 $('.header-search-input-phone').on('keydown', function(e) { console.log(e, new Date()); if (e.key == 'Enter') { var keyword = $(this).val(); if (!keyword) { alert('请输入搜索内容') return } window.location.href = `/search.html?keyword=${keyword}&type=search`; } }) $(".header-search-input-phone").on("search", function() { console.log('搜索内容') var keyword = $(this).val(); if (!keyword) { alert('请输入搜索内容') return } window.location.href = `/search.html?keyword=${keyword}&type=search`; }); //展示产品导航 $('.common-nav-item:contains("产品中心")').hover(function() { var name = $(this).children("a").text().trim(); console.log("导航名", name); if (name == "产品中心") { $(".product-nav-container").show(); } }, function(e) { console.log("失去焦点", e.target); $(".product-nav-container").hide(); }); });