//是否是wap端 function is_wap() { return (document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth) < 900 || !!navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i); } var _htmlFontSize = function() { var clientWidth = document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth; if (!is_wap()) { document.documentElement.style.fontSize = 100 + "px"; document.documentElement.classList.remove('body-wap'); document.documentElement.classList.add('body-pc'); return 100; } document.documentElement.style.fontSize = clientWidth / 7.5 * 2 + "px"; document.documentElement.classList.remove('body-pc'); document.documentElement.classList.add('body-wap'); return clientWidth / 7.5 * 2; }; _htmlFontSize(); //计算内容最小高度 function mianMinHeight() { var winHeight = window.innerHeight || $(window).height(); var headerHeight = $(".header").height(); var footerHeight = $(".footer").height(); var mainHeight = winHeight - headerHeight - footerHeight; if (mainHeight < 100) { mainHeight = 100; } $(".main").css({ "min-height": mainHeight + 'px' }); } //页面滚动执行方法 function scrollWin() { var winWidth = window.innerWidth || $(window).width(); var s = $(window).scrollTop(); if (!is_wap()) { if ($('.header-dynamic').length) { if (s > 10) { if (s > winWidth * 0.25) { $('.header-dynamic').removeClass('header-transparent'); } var o = (s - 10) / (winWidth * 0.5 - 10); if (o > 1) o = 1; $('.header-dynamic .header-fixed').css({ 'background': 'rgba(255,255,255,' + o + ')' }); if (o == 1) { $('.header-dynamic .header-fixed').addClass('line'); } else { $('.header-dynamic .header-fixed').removeClass('line'); } } else { $('.header-dynamic').addClass('header-transparent'); $('.header-dynamic .header-fixed').css({ 'background': 'none' }); } } } // if ($('.scroll_top').length) { // if (s > 100) { // $('.scroll_top').show(); // } else { // $('.scroll_top').hide(); // } // } } //获取菜单(type:0-pc头部,1-wap,2-pc底部) function getMenuHtml(type, current) { current = current || 'index'; var menus = [{ name: '服务分类', href: 'service.html' }, { name: '网站首页', href: 'index.html' }, { name: '创业政策', href: 'policy.html' }, { name: '创业园区', href: 'park.html' }, { name: '新闻资讯', href: 'news.html' }, { name: '关于我们', href: 'about.html' }]; var str = ''; for (var i in menus) { var f = menus[i]; var active = current + '.html' == f.href || current == f.href; str += '
  • ' + f.name + '
  • '; } return str; } //初始化搜索事件 function initSearchEvent() { //最近搜索 var search_history = localStorage.getItem('search_history'); var slist = []; var $recentlist = $('.popup-recent .popup-recent-list'); $recentlist.empty(); if (search_history) { slist = JSON.parse(search_history); slist.forEach(f => { $recentlist.append('' + f + ''); }) } else { $('.header-pc .popup-recent').hide(); } //页面跳转 function goTo(value) { var type = $('.header-pc .search select').val(); if (value && value.trim()) { value = value.trim(); if (slist.indexOf(value) > -1) { slist = slist.filter(f => f != value); } slist.splice(0, 0, value); if (slist.length > 5) { slist.splice(5, slist.length - 5); } localStorage.setItem('search_history', JSON.stringify(slist)); if (window.formalWeb) { switch (type) { case '1': window.location.href = '/policy-0-1-' + value + '.html'; break; case '2': window.location.href = '/park-0-1-' + value + '.html'; break; case '3': window.location.href = '/news/search-' + value + '.html'; break; default: break; } } else { window.location.href = 'news.html?text=' + value; } } else if (window.formalWeb && $("#initSearchType").val()) { switch (type) { case '1': window.location.href = '/policy.html'; break; case '2': window.location.href = '/park.html'; break; default: break; } } } $(".header-pc .search").on('click', function() { if (!$(this).parents('.search-content').length) { $(".header-pc .nav-box .nav").addClass('search-content'); $('.header-pc .search input').focus(); event.stopPropagation(); } }) $(document).on('click', '.header-pc .search-content .icon-search', function() { goTo($('.header-pc .search input').val()); event.stopPropagation(); }) $(document).on('click', '.header-pc .popup-recent .popup-recent-list a', function() { goTo($(this).html()); event.stopPropagation(); }) $(document).on('click', ".header-pc .search .icon-close", function() { $(".header-pc .nav-box .nav").removeClass('search-content'); $('.header-pc .search input').val(''); event.stopPropagation(); }) $(document).on('keypress', '.header-pc .search input', function(event) { if (event.keyCode == 13) { goTo(this.value); } }); $(document).on('focus', '.header-pc .search input', function(event) { $('.header-pc .nav .search .popup-recent').addClass('show'); }); // $(document).on('blur', '.header-pc .search input', function(event) { // $('.header-pc .nav .search .popup-recent').removeClass('show'); // }); // if ($('.header-pc .search input').val()) { // $(".header-pc .search").css("display", "initial"); // } $(".header-yd .trigger,.header-yd .slider-mask-menu").click(function() { $(".header-yd .slider").toggleClass("open"); $('.header-yd .slider-mask-menu').fadeToggle(300); $('.header-yd .trigger').toggleClass("trigger-open"); }); var search_show = false; $(".header-yd .search,.header-yd .slider-mask-search").click(function() { search_show = !search_show; $('.header-yd .slider-mask-search').fadeToggle(300); $('.header-yd .search-form').toggleClass('show'); setTimeout(function() { if (search_show) { $('.header-yd .search-form input').focus(); } else { $('.header-yd .search-form input').blur(); } }, 300) }); $('.header-yd .search-form form').on('submit', function() { var text = $('.header .search-form input').val(); goTo(text); return false; }) $('.header-yd .search-form input').on('keypress', function(event) { if (event.keyCode == 13) { goTo(this.value); } return false; }); //初始化值 if ($("#initSearchValue").val()) { var searchValue = $("#initSearchValue").val() $('.header-pc .search input').val(searchValue); $('.header .search-form input').val(searchValue); $(".header-pc .nav-box .nav").addClass('search-content'); } if ($("#initSearchType").val()) { var searchType = $("#initSearchType").val() $('.header-pc .search select').val(searchType); } } $(function() { initSearchEvent(); mianMinHeight(); window.onresize = function() { _htmlFontSize(); mianMinHeight(); } scrollWin(); $(window).scroll(function() { scrollWin(); }); //自定义事件 $(document).on('click', '[data-event="link"]', function() { var link = $(this).data("link"); var target = $(this).data("target"); if (link) { if (target == "_blank") { window.open(link); } else { window.location.href = link; } } }) $(document).on('click', '[data-event="mao"]', function() { if ($(this).data("id")) { var $demo = $("#" + $(this).data("id")); if ($demo.length) { var headHei = $('.header').height() || 0; var top = $demo.offset().top - headHei; $('html,body').animate({ scrollTop: top + 'px' }, 300); } } }) $(document).on('click', '.con-nav-list .item', function() { if (!$(this).hasClass('active')) { var $list = $($(this).parents('.con-nav-list')[0]); $list.find('.item.active').removeClass('active'); $(this).addClass('active'); } }) $('.scroll_top').click(function() { $('html,body').animate({ scrollTop: '0px' }, 300); }); $(document).on('click', '.menu-toggle', function() { if ($(this).parent().find('.menu-toggle-child.open').length == 0) { $(this).parent().parent().find('.menu-toggle-child.open').css({ height: 0 + 'px' }).removeClass('open'); var height = $(this).parent().find('.menu-toggle-child .box').height(); $(this).parent().find('.menu-toggle-child').css({ height: height + 'px' }).toggleClass('open'); } else { // $(this).parent().find('.menu-toggle-child').css({ // height: 0 // }).removeClass('open'); var height = $(this).parent().find('.menu-toggle-child .box').height(); $(this).parent().find('.menu-toggle-child').css({ height: 0 + 'px' }).toggleClass('open'); } }) if (is_wap() && $('.con-nav .item.active').length) { var boxWid = $('.con-nav-list').width(); var wid = $('.con-nav .item.active').width(); var left = $('.con-nav .item.active').offset().left; var scrollLeft = left - (boxWid - wid) / 2; if (scrollLeft > 0) { $('.con-nav-list').scrollLeft(scrollLeft); } } $(document).on('click', '.tabs .item', function() { // if (!$(this).hasClass('active')) { var $list = $($(this).parents('.tabs')[0]); var index = $list.find('.item').index(this); // $list.find('.item.active').removeClass('active'); // $(this).addClass('active'); var $content = $list.parent().find('.tabs-content'); $content.find('.tabs-content-item.active').removeClass('active'); $($content.find('.tabs-content-item')[index]).addClass('active'); // } }) })