// 导航特效 $(function () { var $lgnavwrapper=$(".lg-nav-wrapper"); var $smnavwrapper=$(".sm-nav-wrapper"); $lgnavwrapper.on("mouseenter",".search-btn",function () {//移入搜索按钮 var $this=$(this); var $parent=$this.parents(".top-search-box"); $parent.addclass("active"); }); $lgnavwrapper.on("mouseleave",".top-search-ipt",function () {//移入输入框 var $this=$(this); var $parent=$this.parents(".top-search-box"); $parent.removeclass("active"); }); $lgnavwrapper.on("mouseenter",".top-search-ipt",function () {//移出输入框 var $this=$(this); var $parent=$this.parents(".top-search-box"); $parent.addclass("active"); }); // $lgnavwrapper.on("mouseenter",".lg-nav>.bottom a,.lg-nav-son",function () {//移入大屏幕菜单 // var $this=$(this); // var $lgnavwrapper=$this.parents(".lg-nav-wrapper"); // var $cnavbox=$this.parents(".c-nav-box"); // if(!$cnavbox.hasclass("fixed")){ // $cnavbox.addclass("fixed"); // } // // if($this.hasclass("lg-nav-son")){} // $lgnavwrapper.addclass("active"); // }); // $lgnavwrapper.on("mouseleave",".lg-nav>.bottom>a,.lg-nav-son",function () {//移出大屏幕菜单 // var $this=$(this); // var $lgnavwrapper=$this.parents(".lg-nav-wrapper"); // var $cnavbox=$this.parents(".c-nav-box"); // var top=$(window).scrolltop(); // if(top<=0){ // $cnavbox.removeclass("fixed"); // } // $lgnavwrapper.removeclass("active"); // }); $smnavwrapper.on("click",".icon-menu",function () { //点击小屏菜单图标 var $this=$(this); var $parent=$this.parents(".c-nav-box"); if(!$parent.hasclass("active")){ $parent.addclass("active fixed"); } else{ $parent.removeclass("active"); var top=$(window).scrolltop(); if(top<=0){ $parent.removeclass("fixed"); } } return false; }); $smnavwrapper.on("click",".nav-list>li .icon-arrow",function () { //点击小屏菜单列表 var $this=$(this); var $li=$this.parents("li"); var $navson=$li.find(".nav-son"); if($navson.length>0){ if(!$li.hasclass("active")){ $li.addclass("active").siblings("li").removeclass("active"); }else{ $li.removeclass("active"); } } return false; }); $(document).on("click",".c-nav-box",function (e) {//点击小屏幕空白消失 if(e.target.nodename!="input"){ var $this=$(this); $this.removeclass("active"); } }); // 页面滚动菜单固定 if($(window).scrolltop()>0){ $(".c-nav-box").addclass("fixed"); }; $(window).scroll(function () { var top=$(window).scrolltop(); var $cnavbox=$(".c-nav-box"); var $partmenu=$(".part-menu"); // 五大模块的快捷菜单 var offset=$partmenu.offset(); if(top>0){ $cnavbox.addclass("fixed"); if(offset){ if(top>=offset.top){ $partmenu.addclass("fixed"); $cnavbox.hide() } } }else{ // 小屏菜单激活时 if($cnavbox.hasclass("active")){ return; } // 大屏菜单激活时 if($lgnavwrapper.hasclass("active")){ return; } if(offset){ $partmenu.removeclass("fixed"); $cnavbox.fadein() } $cnavbox.removeclass("fixed"); } }); $(window).resize(function () { var w=window.innerwidth;//获取加上滚动条的宽度 if(w>750){ //小屏取消激活会影响输入框 var $cnavbox=$(".c-nav-box"); if($cnavbox.hasclass("active")){ $cnavbox.removeclass("active") } } }); $(".part-menu").on("click","a",function () { var $this=$(this); $this.addclass("active").parent("li").siblings("li").find("a").removeclass("active"); }); }); // 收藏效果 $(function () { $(".c-container").on("click", '.like-box',function () { var $this=$(this); if(!$this.hasclass("active")){ $this.addclass("active") } else{ $this.removeclass("active") } }); }); // 招聘特效 $(function () { var $recruitment=$(".recruitment-condition-box"); var $recruitmentmb=$(".recruitment-container-mb"); // 点击筛选条件 $recruitment.on("click","dd",function () { var $this=$(this); if(!$this.hasclass("more-btn")){ $this.addclass("active").siblings("dd").removeclass("active"); } }); // 小屏幕筛选条件 $recruitmentmb.on("click",".recruitment-condition-box a",function () { var $this=$(this); var $parent=$this.parent(".recruitment-condition-box"); var activeindex=$parent.find("a.active").index(); var index=$this.index(); var $conditiondetails=$parent.next(".condition-details"); if(activeindex==index){ if(!$this.hasclass("active")){ $conditiondetails.find(".condition-list").hide().eq(index).fadein(); $parent.find(".active").removeclass("active"); $this.addclass("active"); }else{ $conditiondetails.find(".condition-list").hide(); $parent.find(".active").removeclass("active"); } } else{ $conditiondetails.find(".condition-list").hide().eq(index).fadein(); $parent.find(".active").removeclass("active"); $this.addclass("active"); } }); $recruitmentmb.on("click",".condition-list li",function () { var $this=$(this); $this.addclass("active").siblings("li").removeclass("active"); $this.parents(".condition-list").hide(); $this.parents(".recruitment-container-mb").find(".recruitment-condition-box a.active").removeclass("active"); }) }); // 加载特效 $(function () { // 滚动动画 var scrollanimation={ scrollfn:function () { var that=this; that.scrolldetail(); $(window).scroll(function(){ that.scrolldetail(); }); $(window).resize(function(){ that.scrolldetail(); }); }, scrolldetail:function () { var h=$(window).height(); var y=$(window).scrolltop(); var space=y+h; // 动画 this.setanimation($(".animation-fade-up.init-state"),y,space); // 由下往上浮现 }, setanimation:function ($obj,y,space) { $obj.each(function () { var $this=$(this); var thistop=$this.offset().top; if(thistop <= space){ //滚动显示 settimeout(function () { $this.removeclass("init-state"); },100) } }); }, init:function () { this.scrollfn(); } }; scrollanimation.init(); }); // swiper初始化 function initswiper() { //banner轮播 var $cbannerswiper=$(".c-banner-swiper"); if($cbannerswiper.length>0){ var bannerswiper = new swiper('.c-banner-swiper', { pagination: '.swiper-pagination', paginationtype : 'fraction', paginationclickable: true, autoplay: 5000,//可选选项,自动滑动 observer: true,//修改swiper自己或子元素时,自动初始化swiper observeparents: true,//修改swiper的父元素时,自动初始化swiper onimagesready: function(swiper){ //图片资源加载完毕后,去掉背景,设置位置 swiperimgsize($cbannerswiper); $cbannerswiper.find(".bg-gray").removeclass("bg-gray"); var len=$cbannerswiper.find(".swiper-slide").length; if(len<2){ $cbannerswiper.find(".swiper-pagination ").remove(); }else{ $cbannerswiper.find(".swiper-pagination ").show(); } }, onafterresize: function(swiper){ // 尺寸随窗口变化 swiperimgsize($cbannerswiper); } }); } // 服务案例轮播 var $serviceswiper=$(".service-swiper"); if($serviceswiper.length>0){ var serviceswiper = new swiper('.service-swiper', { slidesperview:'auto', observer: true,//修改swiper自己或子元素时,自动初始化swiper observeparents: true,//修改swiper的父元素时,自动初始化swiper nextbutton: '.swiper-button-next', prevbutton: '.swiper-button-prev', resistanceratio:0, onimagesready: function(swiper){ //图片资源加载完毕后,去掉背景,设置位置 swiperimgsize($serviceswiper); }, onafterresize: function(swiper){ // 尺寸随窗口变化 swiperimgsize($serviceswiper); } }); } // 首页智慧新闻 var $indexnewsswiper=$(".index-news-swiper"); if($indexnewsswiper.length>0){ var indexnewsswiper = new swiper('.index-news-swiper', { pagination: '#swiper-pagination', paginationclickable: true, spacebetween: 10, autoplay: 5000,//可选选项,自动滑动 observer: true,//修改swiper自己或子元素时,自动初始化swiper observeparents: true,//修改swiper的父元素时,自动初始化swiper oninit: function(swiper){ //swiper初始化了 var len=$indexnewsswiper.find(".swiper-slide").length; if(len<2){ $indexnewsswiper.find(".swiper-pagination ").remove(); } }, onimagesready: function(swiper){ //图片资源加载完毕后,去掉背景,设置位置 swiperimgsize($indexnewsswiper); $indexnewsswiper.find(".bg-gray").removeclass("bg-gray"); }, onafterresize: function(swiper){ // 尺寸随窗口变化 swiperimgsize($indexnewsswiper); } }) } } // swiper图片控制 function swiperimgsize($container) { var $img=$container.find(".swiper-img"); var swiperinterval=""; $img.each(function () { var $this=$(this); var imgswiperinterval=""; var $parent=$this.parent(".swiper-slide"); var parentw=$parent.width(); var parenth=$parent.height(); var wnow,ml; if($this.width()==0||$this.height()==0){ imgswiperinterval=setinterval(function () { if($this.height()!=0&&$this.width()!=0) { clearinterval(imgswiperinterval); wnow=parenth*$this.width()/$this.height(); wnow=wnow>parentw?wnow:"100%"; ml=wnow!="100%"?-(wnow-parentw)/2:0; } },30) }else{ wnow=parenth*$this.width()/$this.height(); wnow=wnow>parentw?wnow:"100%"; ml=wnow!="100%"?-(wnow-parentw)/2:0; } $this.css({"width":wnow,"height":parenth,"margin-left":ml+"px"}); }); } // 图片缩放 ;(function ($,window,document,undefined) { var pluginname="imgscale", // 图片从中心缩放、裁剪 (图片外层大小请在css设置) // 配置默认参数 defaults={}; //定义构造函数 构造函数保护了插件的各个参数包括默认参数,然后调用了插件的 prototype 中定义的 init 方法。 function plugin(element,options) { //拿到dom元素,获得对应jq对象,要$(element) this.element = element; //覆盖默认配置项 this.options=$.extend({},defaults,options); //缓存配置项 this._defaults=defaults; //缓存插件名字 this._name=pluginname; //调用初始函数 this.init(); } plugin.prototype= { init: function () { var e = this; var $element = $(e.element); //初始化时的元素 var $imgboxbg=$element.find(".img-scale-box.placeholder-bg"); var $imgs=$element.find(".img-scale-box .img-scale"); e.imginit($imgboxbg); $(window).scroll(function () {//滚动条滚动 var $imgboxbgnow=$element.find(".img-scale-box.placeholder-bg"); if($imgboxbgnow.length>0){ e.imginit($imgboxbgnow); } }); $(window).resize(function () {//监听窗口变化 $imgs.each(function () { var $this=$(this); e.imgload($this); }) }); }, imginit:function ($obj) { //初始化 var e=this; $obj.each(function () { var $this=$(this); if($this.offset().top<=($(window).scrolltop()+$(window).height())){ var $img=$this.find(".img-scale"); e.imgload($img); } }); }, imgload:function ($obj) { var e=this; $obj.attr("src",$obj.attr("data-original-src"));//填充图片 var imginterval=""; if($obj.height()===0||$obj.width()===0){ imginterval=setinterval(function () { if($obj.height()!=0&&$obj.width()!=0) { clearinterval(imginterval); e.imgsizeset($obj); } },150) } else{ e.imgsizeset($obj); } }, imgsizeset:function ($obj) { var $imgbox=$obj.parent(".img-scale-box"); var imgboxw=$imgbox.width();//父元素img-box的宽度 var imgboxh=$imgbox.height();//父元素img-box的高度 var w,h,ml,mt; var imgw=$obj.width();//当前图片的宽度 var imgh=$obj.height();//当前图片的高度 if(imgw/imgh==imgboxw/imgboxh){//比例一致 w=imgboxw; h=imgboxh; ml=0; mt=0; } else{ w=imgw>=imgboxw?imgw:imgboxw; h=imgh>=imgboxh?imgh:imgboxh; ml=imgw>=imgboxw?(imgboxw-imgw)/2+"px":0; mt=imgh>=imgboxh?(imgboxh-imgh)/2+"px":0; } $obj.css({"width":w,"height":h,"margin-left":ml,"margin-top":mt}).fadein('fast',function () { $imgbox.removeclass("placeholder-bg"); }); } } //fn就是prototype $.fn[ pluginname ] = function (options) { //向jquery注册插件 var e = this; return e.each(function(){ if(!$.data(e,'plugin_'+pluginname)){ $.data(e,'plugin_'+pluginname,new plugin(this,options)); } }); }; })(jquery, window, document); // 视频播放 ;(function ($,window,document,undefined) { var pluginname="videolayer", // 配置默认参数 defaults={ src:'',// video路径 autoplay:true,//默认自动播放视频 force_click: true//默认点击背景能关闭 }; //定义构造函数 构造函数保护了插件的各个参数包括默认参数,然后调用了插件的 prototype 中定义的 init 方法。 function plugin(element,options) { //拿到dom元素,获得对应jq对象,要$(element) this.element = element; //覆盖默认配置项 this.options=$.extend({},defaults,options); //缓存配置项 this._defaults=defaults; //缓存插件名字 this._name=pluginname; //调用初始函数 this.init(); } plugin.prototype= { init: function () { var e = this; var $element = $(e.element); //初始化时的元素 $(".video-layer").remove();//移除视频弹出层 //构建元素 var videolayer='
'+ '
'+ '关闭'+ ''+ '
'+ '
'; var $videolayer = $(videolayer); $element.prepend($videolayer); e.addeventlistener(); }, addeventlistener:function () {//移除视频弹出层 var e=this; $(document).on("click",".video-layer .close-btn",function () { $(this).parents(".video-layer").remove(); }); $(document).on("click",".video-layer",function () { if(e.options.force_click){ $(this).remove(); } }); } } //fn就是prototype $.fn[ pluginname ] = function (options) { //向jquery注册插件 var e = this; return e.each(function(){ if(!$.data(e,'plugin_'+pluginname)){ $.data(e,'plugin_'+pluginname,new plugin(this,options)); } }); }; })(jquery, window, document);