var cy = { init: function () { this.setheadernav(); this.setipcbanner(); this.setipcnav(); this.setabout(); this.sethr(); }, setheadernav: function () { var header = $("header"); /* 移动端导航栏 */ var headermenu = header.find('.header-tools'), navmenu = header.find('.header-nav'), wrapper = $('.cy-wrapper'); headermenu.on({ 'click': function () { headermenu.find('.nav-menu').toggleclass('active'); navmenu.toggleclass('show'); wrapper.toggleclass('to-left'); } }); var navitem = $('.nav-item'); cy.setsublink(navitem, '.sub-nav'); navitem.on({ 'click': function () { var _this = $(this), _sublist = _this.find('.sub-nav'), _sib = _this.siblings(), _siblist = _sib.find('.sub-nav'); if ($(window).width() <= 1024) { _this.toggleclass('active'); _sublist.stop().slidetoggle(370); _sib.removeclass('active'); _siblist.slideup(370); } } }); $(window).resize(function () { if ($(window).width() > 1024) { navitem.removeclass('active'); navmenu.removeclass('show'); headermenu.find('.nav-menu').removeclass('active'); wrapper.removeclass('to-left'); } }); var totop = $('.to-top'); function settotop() { if ($(window).width() > 1024) { totop.on({ 'click': function () { $("html,body").animate({ scrolltop: 0 }); } }); } else { totop.off('click'); } } /* 导航滚动监听 */ function navscroll() { if ($(window).scrolltop() > (header.height())) { header.addclass('scroll'); if ($(window).width() > 1024) { totop.fadein(); } else { totop.hide(); } } else { header.removeclass('scroll'); totop.fadeout(); } } navscroll(); $(window).scroll(function () { navscroll(); }); settotop(); $(window).resize(function () { settotop(); }); }, setsublink: function (_navitem, _subitem, _size) { /* * 监听导航栏一级栏目的链接 * _navitem:一级栏目 * _subitem:二级栏目 * _size:屏幕大小 * */ var arr = []; var size = _size || 1024; _navitem.each(function (index) { var _this = $(this), _menu = _this.find(_subitem); arr.push(_menu.siblings("a").attr("href")); if ($(window).width() > size) { _menu.css("display", "").siblings("a").attr("href", arr[index]); } else { _menu.siblings("a").attr("href", "javascript:"); } $(window).resize(function () { if ($(window).width() > size) { _menu.css("display", "").siblings("a").attr("href", arr[index]); } else { _menu.siblings("a").attr("href", "javascript:"); } }); }); }, setipcbanner: function () { if ($('.ipc-banner').length) { var ipcbanner = $(".banner-box"); var banner = $(".banner-pic"), _head = 'header', speed = 2; function bannerscroll() { var headh = $(_head).length ? $(_head).height() : 0; var h = banner.height() + headh; banner.css({ "position": "relative", "top": $(window).scrolltop() > h ? "" : $(window).scrolltop() / speed }).find(".title").css({ "top": $(window).scrolltop() > h ? "" : -$(window).scrolltop() / speed }); } function bannerbox() { if (ipcbanner.length) { if ($(window).width() > 1024) { imgfullscreen(ipcbanner); } else { imgfullscreen(ipcbanner, $(window).width(), ipcbanner.height()); } } } bannerscroll(); bannerbox(); $(window).resize(function () { bannerbox(); }); $(window).scroll(function () { bannerscroll(); }); } }, setipcnav: function () { var ipcnavbar = $('.ipc-navbar'); var _mbtn = $('.current-page'), _mnav = $('.inav-list'); if (ipcnavbar.length) { $('.ipc-banner').imagesloaded(function () { var navbartop = ipcnavbar.offset().top; var snitem = $('.inav-item'); snitem.each(function () { var _this = $(this), _link = _this.find('a'), _anchor = _link.attr('href').split('#')[1]; _link.click(function () { var _anchortop = $('#' + _anchor).offset().top; if ($(window).width() > 1024) { $('html, body').animate({ scrolltop: _anchortop - $('.header').height() - ipcnavbar.height() }, 500); } else { $('html, body').animate({ scrolltop: _anchortop - $('.header').height() }, 500); _mbtn.removeclass('show'); _mnav.removeclass('show'); $('body').removeclass('c'); } return false; }); function setatop() { if ($(window).scrolltop() >= navbartop&&$('.scroll-navbar').length) { var headerh = $('.header').height(), navbarh = ipcnavbar.height(), _atop = $('#' + _anchor).offset().top - headerh - navbarh; if ($(window).scrolltop() >= _atop) { _this.addclass('current').siblings().removeclass('current'); } } } setatop(); $(window).scroll(function () { setatop(); }); }); mnavbar(); snavbar(); $(window).resize(function () { mnavbar(); }); $(window).scroll(function () { snavbar(); }); function mnavbar() { if (ipcnavbar.length) { if ($(window).width() <= 1024) { _mbtn.click(function () { _mbtn.toggleclass('show'); _mnav.toggleclass('show'); $('body').toggleclass('c'); return false; }); _mnav.on({ 'click': function () { _mbtn.removeclass('show'); _mnav.removeclass('show'); $('body').removeclass('c'); } }); $('body').on({ 'click': function () { _mbtn.removeclass('show'); _mnav.removeclass('show'); $('body').removeclass('c'); } }); } else { _mnav.off('click'); $('body').off('click'); } } } function snavbar() { if (ipcnavbar.length) { var headerh = $('.header').height(), navbarh = ipcnavbar.height(), _top = navbartop - headerh - 10; var navbaro = $('.scroll-mmp'); if ($(window).width() > 1024) { if (!navbaro.length) { ipcnavbar.after('
'); } var _t = ($(window).scrolltop() < _top) ? 0 : (navbarh - ($(window).scrolltop() - _top) / 2); navbaro.height(_t); if ($(window).scrolltop() >= _top) { ipcnavbar.addclass('scroll').css({ 'top': headerh }); } else { ipcnavbar.removeclass('scroll').css({ 'top': '' }); } } else { navbaro.remove(); } } } }); } }, setcyajax: function (_url, _target, _call) { $.ajax({ url: _url, datatype: "html", success: function (rel) { _target.append(rel); if (_call == '' || _call == null) { return; } _call(); } }); }, setabout: function () { var aboutcc = $('.about-cc'); if (aboutcc.length) { var _cccarousel = aboutcc.find('.carousel'); _cccarousel.slick({ appendarrows: aboutcc.find('.cc-carousel'), prevarrow: '', nextarrow: '', slidestoshow: 3, responsive: [ { breakpoint: 768, settings: { slidestoshow: 2 } }, { breakpoint: 576, settings: { slidestoshow: 1 } } ] }); } } }; $(function () { cy.init(); }); /* set full screen image */ /* * _item: 图片的盒子 * _width: 输入的宽度,默认为空 * _height: 输入的高度,默认为空 * */ function imgfullscreen(_item, _width, _height) { /* 判断是否存在 img-fs 类,没有则添加 */ if (!_item.hasclass("cy-fs")) { _item.addclass("cy-fs"); if (_item.children("img").length) { _item.children("img").wrap("
"); } else { _item.removeclass('cy-fs'); } } var _fs=_item,/*盒子*/ _fs_c=_fs.find(".fs-c"),/*内容*/ _img=_fs.find("img"); /* 判断是否 有输入的宽高 */ var inputw=_width||'',inputh=_height||''; /* 设置盒子的宽高 */ _fs.css({"width": inputw,"height": inputh}); loadimage(_img.attr("src"),function(img){ var imagew=img.width,imageh=img.height; /* 获取缩放后的图片宽高 */ var scalew=imagew*inputh/imageh,scaleh=imageh*inputw/imagew; /* 计算 输入宽高比,图片比 */ var imager=imagew/imageh,inputr=inputw/inputh; /* 判断 输入宽高比与缩放后的宽高比 */ if (imager > inputr) { _fs_c.css({ "width": '', /* 以输入的高为标准 缩放图片 */ "height": inputh }); /* 设置图片的响应高度 */ _img.css({ "position": "relative", "top": '', /* 设置图片相对位移 */ "left": -(scalew - inputw) / 2, "width": "", "height": "100%" }); } else { _fs_c.css({ /* 以输入的宽为标准 缩放图片 */ "width": inputw, "height": '' }); /* 设置图片的响应宽度 */ _img.css({ "position": "relative", /* 设置图片相对位移 */ "top": -(scaleh - inputh) / 2, "left": '', "width": "100%", "height": "" }); } }) } function loadimage(imgsrc, callback) { var image = new image(); image.src = imgsrc; if (image.complete) { callback(image); image.onload = function () { }; } else { image.onload = function () { callback(image); image.onload = function () { }; }; } }