function stopbubble(e) { // 如果传入了事件对象,那么就是非ie浏览器 if (e && e.stoppropagation) { //因此它支持w3c的stoppropagation()方法 e.stoppropagation(); } else { //否则我们使用ie的方法来取消事件冒泡 window.event.cancelbubble = true; } } var tap = 'ontouchstart' in document ? 'touchstart' : 'click'; //实现滚动条无法滚动 var mo = function(e) { e.preventdefault(); }; /***禁止滑动***/ function scrollstop() { document.body.style.overflow = 'hidden'; document.addeventlistener("touchmove", mo, false); //禁止页面滑动 $('body').height('100vh'); } /***取消滑动限制***/ function scrollmove() { document.body.style.overflow = ''; //出现滚动条 document.removeeventlistener("touchmove", mo, false); $('body').height('auto'); } // 弹框出现 function popoverfun(obj, fn){ var ww = $(window).width(); var $obj = $(obj), $zhe = $obj.find('.popover-zhe'), $inner = $obj.find('.popover-inner'), popfn = fn; $obj.fadein(200, function() { $zhe.show(); if($inner.length > 0){ $inner.fadein(200, function() { $obj.addclass('has-open'); if (popfn != null) popfn(); }); }else{ $obj.addclass('has-open'); if (popfn != null) popfn(); } }) } function popshowfn(obj, fn) { var $obj = $(obj), $zhe = $obj.find('.pop-zhe'), $inner = $obj.find('.pop-inner'), popfn = fn; $obj.fadein(200, function() { $zhe.show(); if($inner.length > 0){ $inner.fadein(200, function() { $obj.addclass('has-open'); if (popfn != null) popfn(); }); }else{ $obj.addclass('has-open'); if (popfn != null) popfn(); } }) } // 弹框隐藏 $('.popover-close, .popover-zhe').on(tap, function(){ var $obj = $(this).parents('.popover-box'); $obj.removeclass('has-open').fadeout(300); scrollmove(); }); $('.pop-close, .pop-cancel').on(tap, function() { $(this).parents('.pop-box').removeclass('open').fadeout(350); }); /// 锚点跳转 function anchormove(id, fn) { var $obj = $(id), movefun = fn; var oh = $obj.offset().top - parseint($('.header').outerheight()) - 40; $('html,body').animate({ scrolltop: oh }, 300, function(){ if(movefun) movefun(); }); }; // 滚动条引用 $(window).on('load', function() { /// 竖向滚动条 if ($('.scrollbox').length > 0) { $('.scrollbox').mcustomscrollbar({ autohidescrollbar: true, advanced:{ updateoncontentresize: true } }); } /// 横向滚动条 if ($('.scrollbox2').length > 0) { $('.scrollbox2').mcustomscrollbar({ axis:"x", mousewheel: false, autohidescrollbar: true }); } }); // 页面滚动wow.js再ie9以上引用 $(window).on('load', function() { var wow = new wow({ boxclass: 'wow', animateclass: 'animated', offset: 100, mobile: true, live: true }); if (!(/msie [6|7|8|9]/i.test(navigator.useragent))) { wow.init(); }; }); // 选项卡按钮 $("[data-toggle='tab'], .tab").off(tap).on(tap, function(){ $(this).addclass('active').siblings().removeclass('active'); }); /***** 头部 ****/ // 搜索按钮 $('.btn-open-sch').off(tap).on(tap, function(event){ stopbubble(event); var ww = $(this).offset().left - $('.head-logo').offset().left + parseint($(this).width()); $('.head-sch .box').show(10, function(){ $(this).css({'width': ww, 'opacity': 1}); }); $('.head-nav-close').stop(true, true).fadeout(150); $('.head-nav-open').removeclass('active'); }); $('.head-sch .box').on(tap, function(event){ stopbubble(event); }); $(window).on('resize', function(){ var ww = $(window).width(); if(ww < 992){ $('.head-sch .box').fadeout(150, function() { $(this).css({'width': 0, 'opacity': 0}); }); }else{ $('.head-sch .box').show().css({'width': '10em', 'opacity': 1}); } }); // $(document).on(tap, function(event){ var ww = $(window).width(); if(ww < 992){ $('.head-sch .box').fadeout(150, function() { $(this).css({'width': 0, 'opacity': 0}); }); } $('.head-nav-close').stop(true, true).fadeout(150); $('.head-nav-open').removeclass('active'); }); // pc端导航 $('.nav-list > li').hover(function(){ var $subnav = $(this).children('.subnav-box'); if($subnav.length > 0){ $subnav.stop(true, true).slidedown(500); } }, function(){ $(this).children('.subnav-box').hide(); }); $('.nav-level2 > li').hover(function(){ $(this).addclass('active').siblings().removeclass('active'); }, function(){ $(this).removeclass('active'); $('.nav-level2 > li.current').addclass('active'); }); // 菜单按钮 $('.head-nav-open').off(tap).on(tap, function(event){ stopbubble(event); $('.head-nav-close').show(); $('.pop-nav-box').addclass('has-open'); scrollstop(); var id = $('.pop-nav-level1 li.current').attr('data-id'); $('.pop-subnav-list .level2-list').hide(); $('#'+id).fadein(350); var ww = $(window).width(); if(ww < 992){ $('.head-sch .box').fadeout(150, function() { $(this).css({'width': 0, 'opacity': 0}); }); } }); $('.pop-nav-box .popover-close').off(tap).on(tap, function(event){ stopbubble(event); $('.head-nav-close').hide(); $('.pop-nav-box').removeclass('has-open'); scrollmove(); }); // 移动端导航 $('.pop-nav-level1 li').off(tap).on(tap, function(){ var id = $(this).attr('data-id'); $(this).addclass('active').siblings().removeclass('active'); $('.pop-subnav-list .level2-list').hide(); $('#'+id).fadein(350); }); /***** 头部 end ****/ // 返回顶部按钮 $(window).on('load scroll', function(){ var wh = $(window).height(), wt = $(window).scrolltop(); if(wt > (wh/2)){ $('.return-top').show(); }else{ $('.return-top').hide(); } }); // 荣誉-轮播 if($('.honor-imgs-box').length > 0){ var honorimgslide = new swiper('.honor-imgs-box', { loop: false, autoplay : 5000, autoplaydisableoninteraction: false, prevbutton:'.swiper-ctrl.prev', nextbutton:'.swiper-ctrl.next', observer:true, observeparents:true, oninit: function(swiper){ if(swiper.slides.length > 1){ $('.swiper-ctrl').show(); }else{ $('.swiper-ctrl').hide() } } }); } // 荣誉-列表 if($('.honor-list-hd').length > 0){ var honortimeslide = new swiper('.honor-list-hd', { loop: false, slidesperview: 'auto', spacebetween: 102, observer:true, observeparents:true, preventclicks : false, breakpoints: { 1600: { spacebetween: 80 }, 1366: { spacebetween: 50 }, 991: { slidesperview: 7, spacebetween: 0 }, 600: { slidesperview: 5, spacebetween: 0 }, 400: { slidesperview: 4, spacebetween: 0 } } }); $('.honor-list-hd a').off(tap).on(tap, function(){ var $li = $(this).parent('li'), ww = parseint($(this).outerwidth()) - parseint($(this).css('padding-left')); var aleft = $li.position().left + honortimeslide.translate, lf = aleft + ww; if($li.index() == ($('.honor-list-hd li').length -1)){ lf = '100%'; } $li.addclass('active').siblings().removeclass('active'); $('.honor-list-hd .timeline').css('width', lf); }); } /// 信息服务 if($('.serv-map').length > 0){ function mappostfn(){ var ratio = parseint($('.serv-map .map').width()) / 522; $('.serv-map .btn-point').each(function(){ var xy = $(this).attr('data-post').split(','); var left = parseint(xy[0]) * ratio, top = parseint(xy[1]) * ratio; $(this).css({ 'left': left, 'top': top }); }); } $(window).on('load resize', function(){ mappostfn(); }); $('.serv-map .btn-point').on('click', function(){ $(this).addclass('active').siblings('.btn-point').removeclass('active'); }); $('.serv-ctrl-list li').on('click', function(){ $(this).addclass('active').siblings().removeclass('active'); }); } /// 清洁直运 if($('.clean-top-slide').length > 0){ var cleantopslide = new swiper('.clean-top-slide', { loop: false, autoplay : 5000, autoplaydisableoninteraction: false, paginationclickable: true, pagination: '.clean-top-ctrl', bulletclass: 'item', bulletactiveclass : 'active', observer:true, observeparents:true, oninit: function(swiper){ if(swiper.slides.length > 1){ $(".clean-top-ctrl").show(); }else{ $(".clean-top-ctrl").hide(); } } }); } /// 卫生填埋 if($('.bss-slide-box').length > 0){ var bssslide = new swiper('.bss-slide-inner', { loop: true, effect : 'coverflow', slidesperview: 2, centeredslides: true, coverflow: { rotate: 0, stretch: 10, depth: 80, modifier: 5, slideshadows : true }, prevbutton:'.bss-slide-arrow.prev', nextbutton:'.bss-slide-arrow.next', paginationclickable: true, pagination: '.bss-slide-ctrl', bulletclass: 'item', bulletactiveclass : 'active', observer:true, observeparents:true, breakpoints: { 767: { slidesperview: 1 } } }); } //// 旅游推荐线路 $(".pc-recom-item-box ul .trl-recom-item").on('mouseenter', function() { $(this).find('.doc-box').stop(true, true).animate({ right: "0%", opacity: 1 }, 300) }).on('mouseleave', function() { $(this).find('.doc-box').stop(true, true).animate({ right: "100%", opacity: 0 }, 300) }); //// 文化旅游 function tramapfn(){ var mapw = parseint($('.travel-map-box').width()), maph = parseint($('.travel-map-box').height()), mratio = mapw / 1920; var mt = maph / 2 * (-1); $('.travel-map-box').css('margin-top', mt); $('.travel-map-item').each(function(){ var xyarr = $(this).attr('data-xy').split(','), txtw = parseint($(this).find('.map-title').width()); var x = xyarr[0] * mratio, y = xyarr[1] * mratio, ml = txtw / 2 * (-1); $(this).css({ 'left': x, 'top' : y }); $(this).find('.map-title').css('margin-left', ml); }); } $(window).on('load', function(){ tramapfn(); }); $(window).resize(function(){ tramapfn(); }); $('.travel-map-item').hover(function(){ $(this).addclass('active').siblings().removeclass('active'); }, function(){ $(this).removeclass('active'); })