function bodyScroll(e){ e.preventDefault(); } $(function() { /*隐藏弹出层*/ $(document).on('click','.pop-box , .js-close',function(){ if($('body>.pop-cont>.js-pop-cont video').length>0){ $(this).parent().find('video')[0].pause(); } var _w=$(window).width()-10; var _h=$(window).height()-10; $('body>.pop-cont').animate({ top: _h*2 },500,function(){ $('body>.pop-cont').hide(); $('body>.pop-cont>.js-pop-cont').hide(100,function(){ $('body>.pop-box').animate({ height: 0 },300,function(){ $('body>.pop-box').width(0).hide() }); }); }); }); $(window).resize(function(){ $('body>.pop-box').css({ width: $(window).width()-10, height: $(window).height()-10 }); }); /*导航展开*/ $(document).on('click','.header .h-nav-btn',function(){ $(this).addClass('ishow'); $('.header .m-h-nav').stop(true,false).animate({ right: 0 }); $('.m-title-box .show-btn').removeClass('ishow'); $('.welc .box1 .left-bar .link-box').stop(true,false).animate({ left: '-101%' }); }); /*导航关闭*/ $(document).on('click','.header .h-nav-btn.ishow',function(){ $(this).removeClass('ishow'); $('.header .m-h-nav').stop(true,false).animate({ right: '-101%' }); }); /*导航下拉*/ $('.header .m-h-nav li .show').click(function(){ if($(this).parent().find('.hide').length>0){ $(this).toggleClass('cur'); $(this).parent().find('.hide').stop(false,true).slideToggle(); $(this).parent().siblings().find('.hide').stop(false,true).slideUp().siblings('.show').removeClass('cur'); return false; } }); $('.header .h-nav li').hover(function(){ $(this).find('.hide').stop(false,true).slideDown(700); },function(){ $('.header .h-nav li .hide').hide(); }); $('.f-nav-btn').click(function(){ $('.header .h-nav-btn.ishow').removeClass('ishow'); $('.header .m-h-nav').addClass('isfixed').stop(true,false).animate({ right: 0 },function(){ $('.header .close-btn').fadeIn(); }); }); $('.header .close-btn').click(function(){ $('.header .close-btn').hide(); $('.header .m-h-nav').stop(true,false).animate({ right: '-101%' },function(){ $('.header .m-h-nav').removeClass('isfixed') $('.header .close-btn').fadeOut(); }); }); /*搜索展开*/ $('.header .search-btn').click(function(){ $('.header .search-box').animate({ right: 0 }); }); /*搜索收起*/ $('.header .search-box .close').click(function(){ $('.header .search-box').animate({ right: -310 }); }); /*首页二级导航*/ $(document).on('click','.m-title-box .show-btn',function(){ $(this).addClass('ishow'); $('.js-sub-list').stop(true,false).animate({ left: 0 }); }); $(document).on('click','.m-title-box .show-btn.ishow',function(){ $(this).removeClass('ishow'); $('.js-sub-list').stop(true,false).animate({ left: '-101%' }); }); $('.js-sub-list .show').click(function(){ if($(window).width()<1005&&$(this).parent().find('.hide').length>0){ $(this).toggleClass('cur'); $(this).parent().find('.hide').stop(false,true).slideToggle(); $(this).parent().siblings().find('.hide').stop(false,true).slideUp().siblings('.show').removeClass('cur'); return false; } }); /*回到顶部*/ $(document).on('click','.header .back-top',function(){ $('html,body').animate({scrollTop:0},{ easing: 'easeInOutQuad', duration: 800 }); }); if($(document).scrollTop()>700){ $('.header .right-bar').fadeIn(); }else{ $('.header .right-bar').fadeOut(); } $(window).scroll(function(){ if($(document).scrollTop()>700){ $('.header .right-bar').fadeIn(); }else{ $('.header .right-bar').fadeOut(); } }); }); // 终端判断 var os = function() { var ua = navigator.userAgent, isWindowsPhone = /(?:Windows Phone)/.test(ua), isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, isAndroid = /(?:Android)/.test(ua), isFireFox = /(?:Firefox)/.test(ua), isChrome = /(?:Chrome|CriOS)/.test(ua), isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)), isPhone = /(?:iPhone)/.test(ua) && !isTablet, isPc = !isPhone && !isAndroid && !isSymbian; return { isTablet: isTablet, isPhone: isPhone, isAndroid : isAndroid, isPc : isPc }; }(); function autoImg(box, speed, number, fadeIn, lCenter, vCenter, auto,toTop) { /*轮播图片*/ var index = 0; var adTimer; /*最外层盒子*/ var wrapBox = $(box); /*图片列表外层盒子*/ var imgUl = $('.js-imgUl', wrapBox); /*图片外层盒子*/ var imgLi = $('.js-imgLi', imgUl); /*图片个数*/ var len = imgLi.length; if(len<10){ $('.text-num .js-all', wrapBox).text('0'+len); }else{ $('.text-num .js-all', wrapBox).text(len); } /*轮播左右按钮*/ var leftBtn = $('.js-left', wrapBox); var rightBtn = $('.js-right', wrapBox); /*轮播分页按钮盒子*/ var pointUl = $('.js-point', wrapBox); /*轮播分页按钮*/ var pointLi = $('li', pointUl); if (number > 1) { if (len <= number) { leftBtn.hide(); rightBtn.hide(); } } else if (number == 1) { if (len == number) { leftBtn.hide(); rightBtn.hide(); pointUl.hide(); } } /*按钮居中*/ if (lCenter) { pointUl.css({ 'margin-left': '-' + pointLi.length * pointLi.outerWidth(true) / 2 + 'px' }); } if (vCenter) { pointUl.css({ 'margin-top': '-' + pointLi.length * pointLi.outerHeight(true) / 2 + 'px' }); } /*计算图片列表外层盒子宽度*/ if (!fadeIn) { imgUl.width(len * imgLi.eq(0).outerWidth(true)); } /*鼠标hover分页按钮触发*/ pointLi.hover(function() { index = $(this).index(); showImg(index); }); imgLi.eq(0).addClass('cur'); /*鼠标移入移出触发*/ if (auto) { wrapBox.hover(function() { clearInterval(adTimer); }, function() { adTimer = setInterval(function() { index++; if (index === Math.ceil(len / number)) { index = 0; } showImg(index); return (index); }, speed); }).trigger("mouseleave"); } else { showImg(index); } /*点击左侧按钮*/ leftBtn.click(function() { index--; if (index < 0) { /*如果能不整除*/ if (len % number !== 0) { index = Math.floor(len / number); } else { /*如果能整除*/ index = Math.floor(len / number) - 1; } } showImg(index); }); /*点击右侧按钮*/ rightBtn.click(function() { index++; if (index === Math.ceil(len / number)) { index = 0; } showImg(index); }); function showImg(_index) { if((_index+1)<10){ $('.text-num .js-index', wrapBox).text('0'+(_index+1)); }else{ $('.text-num .js-index', wrapBox).text((_index+1)); } if (fadeIn) { imgLi.css('z-index', '50').removeClass("cur") .eq(_index).addClass("cur").css('z-index', '51'); pointLi.eq(_index).addClass('cur') .siblings().removeClass('cur'); $('.js-circle .text-box').eq(_index).addClass('cur') .siblings().removeClass('cur'); } else { /*如果个数不能整除且滚动到最后一屏*/ if(!toTop){ if (_index === Math.floor(len / number) && len % number !== 0) { var _w = imgLi.eq(0).outerWidth(true); imgUl.stop(false, true).animate({ 'margin-left': '-' + _w * (len % number + (_index - 1) * number) + 'px' }); pointLi.eq(_index).addClass('cur') .siblings().removeClass('cur'); } else { /*如果能整除*/ var _w = imgLi.eq(0).outerWidth(true); imgUl.stop(false, true).animate({ 'margin-left': '-' + _w * _index * number + 'px' }); pointLi.eq(_index).addClass('cur') .siblings().removeClass('cur'); } }else{ if (_index === Math.floor(len / number) && len % number !== 0) { var _w = imgLi.eq(0).outerHeight(true); imgUl.stop(false, true).animate({ 'margin-top': '-' + _w * (len % number + (_index - 1) * number) + 'px' }); imgLi.eq(_index).addClass("cur").siblings().removeClass("cur"); pointLi.eq(_index).addClass('cur') .siblings().removeClass('cur'); } else { /*如果能整除*/ var _w = imgLi.eq(0).outerHeight(true); imgUl.stop(false, true).animate({ 'margin-top': '-' + _w * _index * number + 'px' }); imgLi.eq(_index).addClass("cur").siblings().removeClass("cur"); pointLi.eq(_index).addClass('cur') .siblings().removeClass('cur'); } } } } } //设置cookie function setCookie(name, value, seconds) { seconds = seconds || 0; //seconds有值就直接赋值,没有为0,这个根php不一样。 var expires = ""; if (seconds != 0 ) { //设置cookie生存时间 var date = new Date(); date.setTime(date.getTime()+(seconds*1000)); expires = "; expires="+date.toGMTString(); } document.cookie = name+"="+escape(value)+expires+"; path=/"; //转码并赋值 } //取得cookie function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); //把cookie分割成组 for(var i=0;i < ca.length;i++) { var c = ca[i]; //取得字符串 while (c.charAt(0)==' ') { //判断一下字符串有没有前导空格 c = c.substring(1,c.length); //有的话,从第二位开始取 } if (c.indexOf(nameEQ) == 0) { //如果含有我们要的name return unescape(c.substring(nameEQ.length,c.length)); //解码并截取我们要值 } } return false; } //清除cookie function clearCookie(name) { setCookie(name, "", -1); }