/*! * cy javascript projects for shuanghu (https://rnmmp.grd) * copyright 2016-2018 code yo, authors own. * licensed under mit, gcc-gcz-gpp (https://rnmmp.grd/aiyongbuyong/aishuobushuo/) * date 2018-3-20 */ var $win = $(window), $header = $('.header'), $footer = $('.footer'), $wrapper = $('.cy-wrapper'), $body = $('body'), $content = $('html,body'), $view = $('.cy-wrapper,.footer'); var winw = window.innerwidth || document.documentelement.clientwidth, winh = window.innerheight || document.documentelement.clientheight; var cy_step; var cy = { init: function () { this.setcommon(); this.setheadernav(); this.setfooter(); this.setipcbanner(); this.setvideo(); this.sethome(); this.sethonor(); this.setspeech(); this.sethr(); this.sethistory(); this.setdialog(); this.setservice(); this.setmore(); this.setanchor(); }, setcommon: function () { var $fancybox = $("[data-fancybox]"); if ($fancybox.length) { $fancybox.fancybox({ slideshow: false, thumbs: false }); } }, setanchor: function () { var _hash = location.hash; $content.scrolltop(0); if (_hash.length) { $content.animate({ scrolltop: $(_hash).offset().top - $header.height() }); } else { $content.scrolltop(0); } }, setheadernav: function () { /* 移动端导航栏 */ var $menu = $header.find('.menu'), $nav = $header.find('.nav'), $nav_item = $header.find('.nav_item'); $menu.click(function () { $menu.toggleclass('act'); $nav.toggleclass('act'); $content.toggleclass('overflow'); }); $nav_item.each(function () { var $this = $(this); $this.click(function (ev) { if ($this.find('ol').length) { if ($win.width() < 1025) { if ($(ev.target).is($nav_item) || $(ev.target).is($nav_item.find('.name'))) { ev.preventdefault(); $this.toggleclass('act'); $this.find('ol').stop().slidetoggle(); } } } }); }); var _pathname = location.pathname; $nav.find('.nav__item').each(function () { var $this = $(this), $link = $this.find('a'); $link.click(function () { var hash = this.hash, pathname = this.pathname; if (hash.length) { if (pathname === _pathname) { var valh = $('.header').height(); if ($win.width() < 1025) { $menu.removeclass('act'); $nav.removeclass('act'); $content.removeclass('overflow'); } smoothscroll($(this.hash), valh); } } }); }); /* 导航滚动监听 */ function navscroll() { if ($win.width() > 1024) { if ($win.scrolltop() > 15) { $header.addclass('scroll').css('top', 0); } else { $header.removeclass('scroll').css('top', 15 - $win.scrolltop()); } } else { $header.css('top', ''); } } navscroll(); $win.scroll(function () { navscroll(); }); $win.resize(function () { navscroll(); }); }, setfooter: function () { setqrpopup('.item', '.popup'); $win.resize(function () { setqrpopup('.item', '.popup'); }); function setqrpopup(item, box, boxcontainer) { var $item = $(item), $box = box, $boxcontainer = $(boxcontainer); if ($win.width() > 1024) { $item.off('click').on({ mouseenter: function () { var $this = $(this), $popup = $this.find($box); $popup.addclass('show'); }, mouseleave: function () { var $this = $(this), $popup = $this.find($box); $popup.removeclass('show'); } }); } else { $item.off('mouseenter mouseleave').on({ click: function (ev) { var $this = $(this), $popup = $this.find($box); $this.siblings().find($box).removeclass('show'); $popup.addclass('show'); if ($(ev.target).is($boxcontainer)) { $popup.removeclass('show'); } } }); } } }, setipcbanner: function () { /*var $banner = $('.cy_banner'); if ($banner.length) { var $more = $('.cy_banner .banner-info .more'); $more.click(function () { $content.animate({ scrolltop: $('.banner-line').offset().top - $('header').height() }); }); }*/ var $nav = $('.cy_inside-nav .nav'); if ($nav.length) { var $nav_link = $nav.find('a'); var _pathname = location.pathname; $nav_link.click(function () { var hash = this.hash, pathname = this.pathname; if (hash.length) { if (pathname === _pathname) { var valh = $('.header').height(); smoothscroll($(this.hash), valh); } } }); } }, setvideo: function () { var $video = $('.video_cy'); if ($video.length) { $video.each(function () { var $this = $(this); $this.find('.vbbox .vicobox').on({ click: function () { if ($(".videobox #videobox").length) { $('#videobox').remove(); } else { $('.videobox').append('
'); $(".vwrap").fadein(); } cyplayer.load({ vcontainer: 'videobox', vfiles: $(this).data("video"), vfimg: $(this).data("img"), repeat:"false", isautoplay: "true" }); } }); }); $(".vwrap .close,.vwrap .videobtg").on({ click: function () { $(".vwrap").hide(function () { $('#videobox').remove(); }); } }); } var $brandvideo = $('.brand_video'); if ($brandvideo.length) { var $carousel = $brandvideo.find('.carousel'); $carousel.slick({ prevarrow: $brandvideo.find('.carousel-arrows .prev'), nextarrow: $brandvideo.find('.carousel-arrows .next'), swipe: false, dots: true, appenddots: $brandvideo.find('.carousel-dots'), custompaging: function() {return "";} }); } }, sethome: function () { var $banner = $('.hm-banner'); if ($banner.length) { var $carousel = $('.hm-banner .carousel'), $dots = $('.hm-banner .dots'); $carousel.on('init', function () { $dots.find('li').eq(0).addclass('cur'); }); $carousel.slick({ autoplay: true, autoplayspeed: 5000, speed: 600, arrows: false, dots: true, appenddots: $dots, fade: true, pauseonfocus: false, pauseonhover: false, custompaging: function(slider, i) {return i+1;} }).on({ 'afterchange': function (event, slick, currentslide) { var _item = $dots.find('li'); _item.eq(currentslide).addclass("cur").siblings().removeclass("cur"); } }); } $('.cy-tg').each(function () { var $this = $(this); if (!$this.hasclass('act')) { $this.addclass('act'); } }); }, sethonor: function () { var $honor = $('.a_honor-info'); if ($honor.length) { var $carousel = $honor.find('.carousel'); $carousel.slick({ prevarrow: $honor.find('.carousel-arrows .prev'), nextarrow: $honor.find('.carousel-arrows .next'), slidestoshow: 5, swipe: false, responsive: [ { breakpoint: 1241, settings: { slidestoshow: 4 } }, { breakpoint: 1025, settings: { slidestoshow: 3 } }, { breakpoint: 577, settings: { slidestoshow: 2 } }, { breakpoint: 426, settings: { slidestoshow: 1 } }] }); } }, setspeech: function () { var $speech = $('#speech-scroll'); if ($speech.length) { $speech.mcustomscrollbar({ theme: "rounded-dots", scrollinertia: 500 }); } }, sethr: function () { var $hr = $('.about_hr'); if ($hr.length) { var $link = $hr.find('.hr-info a'); $link.click(function (ev) { ev.preventdefault(); var $this = $(this); var _src = $this.attr('href'); var _body = $('.hr-body'); var $icon = $this.find('.icon'), $name = $this.find('.name'); if (_body.length) { _body.remove(); } $this.addclass('act'); $.ajax({ url: _src, datatype: "html", success: function (data) { var $_content = $(data).find('.hr-body'); $body.append($_content); var $_body = $('.hr-body'), $_icon = $_body.find('.hr_c-icon'), $_name = $_body.find('.hr_c-name'); $_icon.replacewith($icon.clone()); $_name.replacewith($name.clone()); $_body.fadein().addclass('show'); $content.addclass('overflow'); $header.addclass('scrollbar'); $view.addclass('scrollbar'); function hide() { $_body.addclass('hide').fadeout(function () { $content.removeclass('overflow'); $header.removeclass('scrollbar'); $view.removeclass('scrollbar'); $_body.remove(); $this.removeclass('act'); }); } $_body.click(function (ev) { if ($(ev.target).is($_body) || $(ev.target).is('.container')) { hide(); } }); $('.hr-body .icon-close').click(function () { hide(); }); } }); }); } }, sethistory: function () { var $history = $('.brand_history'); if ($history.length) { var $bhcontent = $('.bh-content'), $carousel = $bhcontent.find('.carousel'); var $line_s = $('.bh_line .line2'), $line = $('.bh_line .line1'), $dot = $('.bh_line .dots'); var _date = [[0, -74],[82, -84],[140, 48], [175, -40], [225, 50], [320, 140], [400, 250], [460, 160], [550, 100], [630, -15], [720, 280], [790, 330], [850, 690], [910, 350], [970, 400], [1040, 180], [1110, 350], [1200, 460], [1290, 560], [1290, 580], [1290, 600]]; $carousel.find('.carousel-item').each(function () { var $this = $(this), $date = $this.find('.date'); var i = $this.index(); $dot.append('' + $date.text() + '') }); $line.css('height', _date[$carousel.find('.carousel-item').last().index()][0] + $win.height()*2/3); $carousel.slick({ prevarrow: $bhcontent.find('.carousel-arrows .prev'), nextarrow: $bhcontent.find('.carousel-arrows .next'), swipe: false, fade: true, speed: 0, adaptiveheight: true, infinite: false }); $dot.find('span').each(function () { var $this = $(this); $this.click(function () { $carousel.slick('slickgoto', $this.index()); }); }); var _bhotop = $bhcontent.offset().top; var _index = 0; var _fixedtop = $history.offset().top - $header.height(); function bhscroll() { var _eletop = $history.offset().top - $header.height(), _srltop = $win.scrolltop(), _elebtm = $history.offset().top + $history.height() + $bhcontent.height() - $header.height(), _srlbtm = $win.scrolltop() + $win.height(), _clitop = _eletop - _srltop, _clibtm = _elebtm - _srlbtm; if (_clitop < 0) { $bhcontent.addclass('fixed').css({ top: _bhotop - _fixedtop }); if (_clibtm < 0) { if (_srltop > _elebtm) { $bhcontent.removeclass('fixed').css({top: ''}); } else { $bhcontent.css({top: _bhotop - _fixedtop + _clibtm}); } } } else { $bhcontent.removeclass('fixed').css({top: ''}); _fixedtop = _srltop; } var _linetop = $line_s.offset().top - $header.height() - $win.height()*2/3; if (_srltop > _linetop) { $line_s.css('height',(_srltop - _linetop)); if ($line_s.height() > $line.height()) { $line_s.css('height', $line.height()); } } else { $line_s.css('height', ''); } $dot.find('span').each(function () { var $this = $(this); var _top = $this.position().top + $dot.position().top; if ($line_s.height() > _top) { _index = $this.index(); } }); $carousel.slick('slickgoto', _index); } $win.scroll(function () { bhscroll(); }); } }, setdialog: function () { var $dialogbtn = $('.dialog_cy-btn'); if ($dialogbtn.length) { var $dialog = $('.dialog_cy'), $dialogitem = $dialog.find('.dialog-c_item'), $btn = $dialogbtn.find('.dialog-btn'), $servicesystem = $('.service_system'); $btn.click(function () { var $this = $(this); $this.addclass('act'); $servicesystem.addclass('show_dialog'); $dialog.fadein().addclass('show'); $dialogitem.eq($this.index()).addclass('z'); $content.addclass('overflow'); $header.addclass('scrollbar'); $view.addclass('scrollbar'); }); $dialog.click(function (ev) { if ($(ev.target).is($dialog) || $(ev.target).is('.dialog-content')) { hide(); } }); $dialog.find('.icon-close').click(function () { hide(); }); function hide() { $dialog.addclass('hide').fadeout(function () { $servicesystem.removeclass('show_dialog'); $content.removeclass('overflow'); $header.removeclass('scrollbar'); $view.removeclass('scrollbar'); $dialog.removeclass('show hide'); $dialogitem.removeclass('z'); $btn.removeclass('act'); }); } } }, setservice: function () { var $serviceadviser = $('.service_adviser'); if ($serviceadviser.length) { var $aitem = $serviceadviser.find('.a-i_item'); $aitem.each(function () { var $this = $(this), $title = $this.find('.a-i_head'), $cont = $this.find('.a-i_body'); $title.click(function () { $this.toggleclass('act'); $cont.stop().slidetoggle(); }); }); } var $serviceby = $('.service_by'); if ($serviceby.length) { var $tabbtn = $('.tab-btn .t-b_item'), $tabcontent = $('.tab-content .t-c_item'); $tabbtn.click(function () { var $this = $(this); $this.addclass('act').siblings().removeclass('act'); $tabcontent.eq($this.index()).addclass('act').siblings().removeclass('act'); }); } var $joindata = $('.join-data'); if ($joindata.length) { var $carousel = $joindata.find('.carousel'), $dots = $joindata.find('.carousel-dots'); $carousel.slick({ arrows: false, dots: true, appenddots: $dots, pauseonfocus: false, pauseonhover: false, custompaging: function() {return '';}, slidestoshow: 4, slidestoscroll: 4, infinite: false, responsive: [ { breakpoint: 1241, settings: { slidestoshow: 3, slidestoscroll: 3 } }, { breakpoint: 769, settings: { slidestoshow: 2, slidestoscroll: 2 } }, { breakpoint: 426, settings: { slidestoshow: 1, slidestoscroll: 1 } }] }); } }, setmore: function () { /*var $sidenav = $('.side-nav'); if ($sidenav.length) { var $totop = $sidenav.find('.to-top'); $totop.click(function () { $content.stop().animate({scrolltop: 0}); }); $win.scroll(function () { if ($win.scrolltop() > $win.height()/2) { $totop.addclass('s'); } else { $totop.removeclass('s') } }); }*/ var $banner = $('.banner_para'); if ($banner.length) { if ($win.width() > 1024) { $win.scroll(function () { if ($win.scrolltop()<$banner.height()) { $banner.find('.banner-pic .pic').css({ 'background-position-y': math.round(($win.scrolltop()/$banner.height())*($win.height()/3))+'px' }); } }); } } var $para = $('.cy_para'); if ($para.length) { cy_step=($(window).width() > 1024)?30:''; $(window).resize(function () { cy_step=($(window).width() > 1024)?30:''; }); var init_index = 0, // init_top = $para.first().offset().top, init_btm = $para.first().offset().top + $para.first().outerheight(); $win.scroll(function () { para(); }); function para() { if ($win.width() > 1024) { // var scroll_top = $win.scrolltop(); var scrollbtm = $win.scrolltop()+$win.height(); $para.each(function (index) { var $this = $(this); // var _top = $this.offset().top; var _btm = $this.offset().top+$this.outerheight(); // if (scroll_top > _top) { if (scrollbtm > _btm) { init_index = index; // init_top = _top; init_btm = _btm; } }); // var scroll_h = parseint(scroll_top - init_top); var scroll_h = parseint(scrollbtm - init_btm); // if (scroll_top > init_top) { if (scrollbtm > init_btm) { $para.eq(init_index+1).css({ 'margin-top': -math.round(scroll_h * .7) + 'px' }); $para.eq(init_index-1).removeclass('cy_cur'); $para.eq(init_index).addclass('cy_cur'); $para.eq(init_index+1).addclass('cy_cur'); $para.eq(init_index+2).removeclass('cy_cur'); } else { $para.css('margin-top', '').removeclass('cy_cur'); } } else { $para.css('margin-top', '').removeclass('cy_cur'); } } } }, setsmooth: function () { (function(){var defaultoptions={framerate:150,animationtime:700,stepsize:cy_step||120,pulsealgorithm:true,pulsescale:8,pulsenormalize:1,accelerationdelta:20,accelerationmax:1,keyboardsupport:true,arrowscroll:50,fixedbackground:true,excluded:''};var options=defaultoptions;var isexcluded=false;var isframe=false;var direction={x:0,y:0};var initdone=false;var root=document.documentelement;var activeelement;var observer;var refreshsize;var deltabuffer=[];var ismac=/^mac/.test(navigator.platform);var key={left:37,up:38,right:39,down:40,spacebar:32,pageup:33,pagedown:34,end:35,home:36};var arrowkeys={37:1,38:1,39:1,40:1};function inittest(){if(options.keyboardsupport){addevent('keydown',keydown)}}function init(){if(initdone||!document.body)return;initdone=true;var body=document.body;var html=document.documentelement;var windowheight=window.innerheight;var scrollheight=body.scrollheight;root=(document.compatmode.indexof('css')>=0)?html:body;activeelement=body;inittest();if(top!=self){isframe=true}else if(isoldsafari&&scrollheight>windowheight&&(body.offsetheight<=windowheight||html.offsetheight<=windowheight)){var fullpageelem=document.createelement('div');fullpageelem.style.csstext='position:absolute; z-index:-10000; top:0; left:0; right:0; height:'+root.scrollheight+'px';document.body.appendchild(fullpageelem);var pendingrefresh;refreshsize=function(){if(pendingrefresh)return;pendingrefresh=settimeout(function(){if(isexcluded)return;fullpageelem.style.height='0';fullpageelem.style.height=root.scrollheight+'px';pendingrefresh=null},500)};settimeout(refreshsize,10);addevent('resize',refreshsize);var config={attributes:true,childlist:true,characterdata:false};observer=new mutationobserver(refreshsize);observer.observe(body,config);if(root.offsetheight<=windowheight){var clearfix=document.createelement('div');clearfix.style.clear='both';body.appendchild(clearfix)}}if(!options.fixedbackground&&!isexcluded){body.style.backgroundattachment='scroll';html.style.backgroundattachment='scroll'}}function cleanup(){observer&&observer.disconnect();removeevent(wheelevent,wheel);removeevent('mousedown',mousedown);removeevent('keydown',keydown);removeevent('resize',refreshsize);removeevent('load',init)}var que=[];var pending=false;var lastscroll=date.now();function scrollarray(elem,left,top){directioncheck(left,top);if(options.accelerationmax!=1){var now=date.now();var elapsed=now-lastscroll;if(elapsed