// javascript document
$(document).ready(function() {
new wow().init();
lazyimg('data-lazy');
//导航
new nav('.nav','.nav-btn',{'navwidth':false});
// $('body').addclass('body-show');
layui.use('layer', function(){
var layer = layui.layer;
//相册弹层
layer.photos({
photos: '#layer-photos'
,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
,shade: .85
});
})
//语言
$('.lang-btn dt').click(function(){
if(phoneis()){
animswitch('.lang-btn');
}
});
$('.lang-btn').mouseenter(function(){
if(!phoneis() && $(this).find('.e-anim-hide').length){
animon(this);
}
});
$('.lang-btn').mouseleave(function(){
if(!phoneis() && $(this).find('.e-anim-hide').length){
animoff(this);
}
});
//footer
$('.footer-bg .nav-share-btn dl').mouseenter(function(){
if(!phoneis() && $(this).find('.e-anim-hide').length){
animon(this);
}
});
$('.footer-bg .nav-share-btn dl').mouseleave(function(){
if(!phoneis() && $(this).find('.e-anim-hide').length){
animoff(this);
}
});
//字体大小
var fontsize = ['f-minn','f-min','f-medium','f-max','f-maxx'];
$('.font-btn').click(function(){
var i = 0;
var fontis = false;
//判断加减
if($(this).hasclass('font-enlarge')){
i = 1;
}else{
i = -1;
}
//获取当前字体尺寸
var size = parseint($('.news-content').attr('data-size'));
//新尺寸
size = size+i;
//赋值新的尺寸
if( i < 0){
if(size >= 0){
fontis =true;
}
}else{
if(size <= fontsize.length-1){
fontis =true;
}
}
if(size >= fontsize.length-1 || size <= 0){
$(this).addclass('font-btn-off');
}else{
$('.font-btn').removeclass('font-btn-off');
}
if(fontis){
$('.news-content').attr('data-size',size);
$('.news-content').removeclass('f-maxx f-max f-medium f-min f-minn').addclass(fontsize[size]);
}
})
//实用简易切换普通
$('.tabs-box-ord').each(function(){
$(this).find('.hd-ord>*').eq(0).addclass('on');
$(this).find('.bd-ord>*').eq(0).show().siblings().hide();
$(this).find('.bdl-ord>*').eq(0).show().siblings().hide();
})
$('.tabs-box-ord .hd-ord>*').on('click',function(){
$(this).addclass('on').siblings().removeclass('on');
$(this).parents('.tabs-box-ord').find('.bd-ord>*').eq($(this).index()).show().siblings().hide();
$(this).parents('.tabs-box-ord').find('.bdl-ord>*').eq($(this).index()).show().siblings().hide();
/* tabsressize(this);*/
})
$('.tabs-box-ord .hd-ord>*').on('mouseenter',function(){
if($(this).parents('.tabs-box-ord').hasclass('tabs-box-enter')){
$(this).addclass('on').siblings().removeclass('on');
$(this).parents('.tabs-box-ord').find('.bd-ord>*').eq($(this).index()).show().siblings().hide();
$(this).parents('.tabs-box-ord').find('.bdl-ord>*').eq($(this).index()).show().siblings().hide();
/*tabsressize(this);*/
}
})
//简易切换动画版
//遍历
$('.tabs-box').each(function(){
$(this).find('.hd>*').eq(0).addclass('on');
$(this).find('.bd>*').eq(0).addclass('tabs-on e-animte-show').siblings().addclass('tabs-hide');
$(this).find('.bdl>*').eq(0).show().siblings().hide();
/*$(this).find('.bd').css('height',$(this).find('.tabs-on').outerheight());*/
})
//切换事件
$('.tabs-box .hd>*').on('click mouseenter',function(e){
if($('.nav-box .container').outerwidth()<960){
stopdefault(e);
}
if(!$(this).hasclass('on')){
$(this).parents('.tabs-box').find('.bd>*').removeclass('tabs-on');
$(this).addclass('on').siblings().removeclass('on');
$(this).parents('.tabs-box').find('.bd>*').eq($(this).index()).addclass('tabs-show e-animte-show').removeclass('tabs-hide').siblings().removeclass('tabs-show e-animte-show').addclass('tabs-hide');
$(this).parents('.tabs-box').find('.bdl>*').eq($(this).index()).show().siblings().hide();
/*$(this).parents('.tabs-box').find('.bd').css('height',$(this).parents('.tabs-box').find('.tabs-show').outerheight());*/
}
})
//窗口改变重置大小
$(window).resize(function() {
settimeout( function(){
/* $('.tabs-box').each(function(){
if($(this).find('.e-animte').hasclass('tabs-on')){
$(this).find('.bd').css('height',$(this).find('.tabs-on').outerheight());
}else{
$(this).find('.bd').css('height',$(this).find('.tabs-show').outerheight());
}
})*/
}, 300 );//延迟重置兼容swiper2.x
});
//滑动监听
var th,tht;
$(window).on('touchstart',function(e) {
clearinterval(tht);
th = 0;
});
$(window).scroll(function(e) {
clearinterval(tht);
$('.float-box').addclass('float-box-hide');
th = 0;
if($(window).height()>$(document).scrolltop()){
$('.top-btn').addclass('top-btn-dn');
$('.message-info').addclass('message-info-min');
}else{
$('.top-btn').removeclass('top-btn-dn');
$('.message-info').removeclass('message-info-min');
}
tht = setinterval(function(){
th++;
if(th>5){
clearinterval(tht);
$('.float-box').removeclass('float-box-hide');
clearinterval(tht);
}
}, 50);
});
//阻止跳转
$('.copy-btn').click(function(){
var e = $(this).attr('data-copy');
$(e).select(); // 选择对象
document.execcommand("copy"); // 执行浏览器复制命令
layer.msg('复制邮箱成功!',{time:1000});
});
//底部分享按钮
$('.share-btn').mouseenter(function(){
$(this).find('.e-animte').addclass('e-animte-show footer-btn-mess-show');
})
$('.share-btn').mouseleave(function(){
$(this).find('.e-animte').removeclass('e-animte-show footer-btn-mess-show');
})
//浏览器版本提示
mybrowser();
var tips ="
您当前的浏览器版本过低,网站部分功能将无法正常显示,请更新您的浏览器。
";
if (mybrowser() == "ff") {
}
if (mybrowser() == "opera") {
}
if (mybrowser() == "safari") {
}
if (mybrowser() == "ie55") {
$("body").prepend(tips);
}
if (mybrowser() == "ie6") {
$("body").prepend(tips);
}
if (mybrowser() == "ie7") {
$("body").prepend(tips);
}
if (mybrowser() == "ie8") {
$("body").prepend(tips);
}
});
var sizetimer = null;
//浏览器版本判断
function mybrowser(){
var useragent = navigator.useragent; //取得浏览器的useragent字符串
var isopera = useragent.indexof("opera") > -1; //判断是否opera浏览器
var isie = useragent.indexof("compatible") > -1 && useragent.indexof("msie") > -1 && !isopera; //判断是否ie浏览器
var isff = useragent.indexof("firefox") > -1; //判断是否firefox浏览器
var issafari = useragent.indexof("safari") > -1; //判断是否safari浏览器
if (isie) {
var ie5 = ie55 = ie6 = ie7 = ie8 = false;
var reie = new regexp("msie (\\d+\\.\\d+);");
reie.test(useragent);
var fieversion = parsefloat(regexp["$1"]);
ie55 = fieversion == 5.5;
ie6 = fieversion == 6.0;
ie7 = fieversion == 7.0;
ie8 = fieversion == 8.0;
if (ie55) {
return "ie55";
}
if (ie6) {
return "ie6";
}
if (ie7) {
return "ie7";
}
if (ie8) {
return "ie8";
}
}//isie end
if (isff) {
return "ff";
}
if (isopera) {
return "opera";
}
}
//swiper2.x,auto显示数量
function swipersl(cla,obj,ss,mm,ll){
swiperdx(cla,obj,ss,mm,ll);
$(window).resize(function() {
swiperdx(cla,obj,ss,mm,ll);
});
}
function swiperdx(c,o,s,m,l){
var w = $('.container').outerwidth();
var x = $(c).outerwidth();
if(w>=960){
$(c).find('.swiper-slide').css('width',x/l);
}else if(w>=720){
$(c).find('.swiper-slide').css('width',x/m);
}else{
$(c).find('.swiper-slide').css('width',x/s);
}
o.resizefix();
}
//阻止冒泡事件
function propagation(){
if (event.stoppropagation) {
// this code is for mozilla and opera
event.stoppropagation();
}
else if (window.event) {
// this code is for ie
window.event.cancelbubble = true;
}
}
//阻止跳转
function stopdefault(e) {
if ( e && e.preventdefault )
e.preventdefault();
else
window.event.returnvalue = false;
return false;
}
//设备横竖屏判断
window.addeventlistener("onorientationchange" in window ? "orientationchange" : "resize", function() {
//竖屏
if (window.orientation === 180 || window.orientation === 0) {
$('html').removeclass('landscape');
}
//横屏时提示
if (window.orientation === 90 || window.orientation === -90 ){
$('html').addclass('landscape');
}
}, false);
//图片懒加载
var inum;
var inums = [];
function lazyimg(lazyname) {
inum = '['+lazyname+']';
$(inum).attr('src','data:image/gif;base64,r0lgodlhaqabaiaaaaaaap///yh5baeaaaaalaaaaaabaaeaaaibraa7');
//遍历图片
for(var i = 0 ; i < $(inum).length; i++){
//遍历父级计算总高度
var top = $(inum)[i].offsettop;
var parent = $(inum)[i].offsetparent;
while(parent != null) {
top += parent.offsettop;
parent = parent.offsetparent;
}
//遍历父级是否隐藏
var showis = true;
var pp = $(inum).eq(i).parent();
while($(pp)[0].tagname != "html"){
if(!$(pp).is(':visible')){
showis = false;
}
pp = $(pp).parent();
}
inums.push({"num":i,"obj":inum,"src":$(inum).eq(i).attr(lazyname),"top":top,"height":top+$(inum).eq(i).height(),"showis":showis});
}
uqimg();
settimeout(function(){uqimg()},1000);
$(window).scroll(function() {
uqimg();
});
}
//更新图片
function uqimg(){
var wt = $(document).scrolltop();
var wh = $(document).scrolltop()+$(window).height();
for(var i in inums){
if(inums[i].top > wt && inums[i].top < wh && inums[i].showis){
$(inum).eq(inums[i].num).attr('src',inums[i].src);
inums.splice(i,1);
}
}
for(var i in inums){
if(inums[i].height > wt && inums[i].height < wh && inums[i].showis){
$(inum).eq(inums[i].num).attr('src',inums[i].src);
inums.splice(i,1);
}
}
for(var i in inums){
if(inums[i].top < wt && inums[i].height > wh && inums[i].showis){
$(inum).eq(inums[i].num).attr('src',inums[i].src);
inums.splice(i,1);
}
}
}
//视频背景居中
function bgvideo(id,opt){
var bgvideo = document.getelementbyid(id);
var vidh = opt.height?opt.height:document.body.offsetwidth;
var videowh,videovw,videovh,videotime;
//视频初始化
bgvideo.onresize = function(){
videosize();
}
document.read = function(){
cleartimeout(videotime)
videotime = settimeout(function(){videosize()},50);
}
addeventonload(function(){
cleartimeout(videotime)
videotime = settimeout(function(){videosize()},50);
})
addeventonresize(function(){
cleartimeout(videotime)
videotime = settimeout(function(){videosize()},50);
})
//视频背景缩放计算
function videosize(){
videovw = bgvideo.videowidth;
videovh = bgvideo.videoheight;
videowh =videovw/videovh;
var windoww = document.documentelement.clientwidth;
var windowh = vidh;
//宽高比例比较
if( windoww / windowh > videowh ){
// bgvideo.classlist.add('video-bg-w');
// bgvideo.classlist.remove('video-bg-h');
bgvideo.style.width = windoww+'px';
bgvideo.style.height = windoww/videowh+'px';
}else{
// bgvideo.classlist.add('video-bg-h');
// bgvideo.classlist.remove('video-bg-w');
bgvideo.style.height = windowh+'px';
bgvideo.style.width = windowh*videowh+'px';
}
}
}
//多个ready
function addeventready(fn){
var originfn = document.ready
document.ready =function () {
originfn && originfn()
fn()
}
}
//多个onload
function addeventonload(fn){
var originfn = window.onload
window.onload =function () {
originfn && originfn()
fn()
}
}
//多个onresize
function addeventonresize(fn){
var originfn = window.onresize
window.onresize =function () {
originfn && originfn()
fn()
}
}
//导航
function nav(cla,btn,opt){
//opt接受的参数
var navwidth = true;
if(opt){
navwidth = opt.navwidth;
}
if($('.nav-list li .on').length == 0){
$('.nav-list li').eq(0).find('a').addclass('on');
}
//移动端导航事件
$(btn).click(function(event){
propagation();
//回到顶部
$('html,body').animate({scrolltop:0},100);
$(btn).toggleclass('nav-btn-show');
if(!$(btn).hasclass('nav-btn-show')){
closenav()
}
animswitch(cla);
});
//手机版带二级阻止跳转
$(cla).find('li>a').click(function(e){
if(phoneis() && $(this).next('.nav-list-sub').length>0){
stopdefault(e);
}
})
//手机点击导航
$('.nav li').click(function(){
if(phoneis()){
$('.nav-list-sub').css('height',0);
$('.nav-list-sub .e-anim-on').each(function(){
animoff(this);
});
if($(this).find('.nav-list-sub').length){
$(this).toggleclass('nav-on').siblings().removeclass('nav-on');
}
if($(this).hasclass('nav-on')){
animon($(this).find('.e-anim-hide'));
}else{
animoff($(this).find('.e-anim-hide'));
}
//获取高度
var navsubh = $(this).hasclass('nav-on') ? $(this).find('.nav-list-height').outerheight() : 0;
$(this).find('.nav-list-sub').css('height',navsubh);
}
});
//导航拦截冒泡
$('.nav-box').click(function(){
propagation();
});
//防ie抖动
$('.nav-list li .on .nav-btn-bg').css({'width':$('.nav-list .on').parent().outerwidth()})
//pc导航鼠标经过
$(cla).find('li').mouseenter(function(){
if(!phoneis()){
$(cla).find('li').removeclass('nav-on');
$(this).addclass('nav-on').siblings().addclass('nav-off');
if($(this).find('.nav-list-sub').length>0){
animon($(this).find('.e-anim-hide'));
}
//导航滑块
if($('.nav-list li .on').length >= 1){
$('.nav-list li .on .nav-btn-bg').css({'left':$(this).offset().left-$('.nav-list .on').offset().left,'width':$(this).width()})//个别特殊网站可加入误差修正
}else{
$('.nav-btn-bg-02').addclass('nav-btn-bg-02-show').css({'left':$(this).offset().left-$('.nav-list').offset().left-1,'width':$(this).width()})
}
if($(this).find('.nav-list-height').length>0){
//二级下拉背景色
$('.nav-list-sub-bg').addclass('e-animte-show nav-list-sub-bg-show');
}
//下拉偏移
if(navwidth){
navl(this);
}
//二级选中
if($(this).find('.nav-list-sub .on').length){
var subon = $(this).find('.nav-list-sub .on');
$(this).find('.nav-list-sub .btn-sub-bg').css({'left':subon.find('span').offset().left-subon.parent().offset().left,'width':subon.find('span').width(),'transition-duration':'0s'})
}
}
});
//pc导航鼠标离开
$(cla).find('li').mouseleave(function(){
if(!phoneis()){
$(this).removeclass('nav-on').siblings().removeclass('nav-off');
$('.nav-list li .on .nav-btn-bg').removeattr('style');
$('.nav-list li .on .nav-btn-bg').css({'width':$('.nav-list .on').parent().outerwidth()})
if($(this).find('.e-anim-hide').length){
var el = $(this).find('.e-anim-hide');
animoff(el,{fun:function(){
el.parent().css({'width':''})
}});
}
//二级下拉背景色
$('.nav-list-sub-bg').removeclass('e-animte-show nav-list-sub-bg-show');
}
$(this).find('.btn-sub-bg').css({'width':'','left':''})
});
//pc导航鼠标二级
/* $(cla).find('.nav-list-sub a').mouseenter(function(){
$(this).parent().find('.btn-sub-bg').css({'left':$(this).find('span').offset().left-$(this).parent().offset().left,'width':$(this).find('span').width(),'transition-duration':''})
});
*/
$('.nav-list').mouseleave(function(){
$('.nav-btn-bg-02').removeclass('nav-btn-bg-02-show').removeattr('style');
})
}
//收起导航
function closenav(){
$('.nav-list-sub').css('height',0);
$('.nav-list li').removeclass('nav-on');
$('.nav .e-anim-on').each(function(){
animoff(this);
})
}
//切换动画
function animswitch(obj,onopt,offopt){
var el;
if($(obj).hasclass('e-anim-hide')){
el = $(obj);
}else{
el = $(obj).children('.e-anim-hide');
}
if(!el.hasclass('e-anim-on')){
animon(obj,onopt)
}else{
animoff(obj,offopt)
}
}
//添加动画
function animon(obj,opt){
var fun;
if(opt){
fun = opt.fun?opt.fun:'';
}
var el;
if($(obj).hasclass('e-anim-hide')){
el = $(obj);
}else{
el = $(obj).children('.e-anim-hide');
}
el.addclass('e-anim-on').removeclass('e-anim-off');
el[0].addeventlistener('animationend', function (e) {
if(e.target === this){
//回调
fun?fun(obj):'';
}
});
}
//移除动画
function animoff(obj,opt){
var fun;
var removeoff = true;//动画结束后是否移除 e-anim-off
if(opt){
fun = opt.fun?opt.fun:'';
opt.removeoff?removeoff = opt.removeoff:'';
}
var el;
if($(obj).hasclass('e-anim-hide')){
el = $(obj);
}else{
el = $(obj).children('.e-anim-hide');
}
el.removeclass('e-anim-on').addclass('e-anim-off');
el[0].addeventlistener('animationend', function (e) {
if(e.target === this){
//回调
fun?fun(obj):'';
removeoff?el.removeclass('e-anim-off'):'';
}
});
}
//获取左偏移值
function navl(obj){
if(!phoneis()){
$(obj).find('.nav-list-sub').removeattr('style');
var pl = 0;
parentleft(obj);
var lmax = pl + $(obj).find('.nav-list-height').outerwidth()-$('.container-header').position().left;
//判断左偏移加宽度是否超出
if(lmax > $('.nav-box .container').width()){
var l = $('.nav-box .container').width() - lmax;
$(obj).find('.nav-list-sub').css('width',$(obj).find('.nav-list-height').outerwidth()+1);
$(obj).find('.nav-list-sub').css('left',l);
}else{
$(obj).find('.nav-list-sub').css('width',$(obj).find('.nav-list-height').outerwidth()+1);
}
}else{
$('.nav-list-sub').css('width','');
}
//递归到body
function parentleft(obj){
if(!$(obj).is('body')){
parentleft($(obj).parent())
}
pl += $(obj).position().left;
}
}
//网站类型
function phoneis() {
if($('.nav-box .container').outerwidth()<960){
return true
}else{
return false;
}
}
//移除样式
function removenewsstyle(cla){
var p = cla+' p';
var span = cla+' span';
var strong = cla+' strong';
var img = cla+' img';
//新闻过滤样式
$(p+','+span+','+strong).each(function(index,el){
//过滤样式
var ta = $(this).css("text-align");
var col = $(this).css("color");
$(this).removeattr('style');
$(this).css('text-align',ta);
$(this).css('color',col);
//居中去掉缩进
if(ta == "center"){
$(this).addclass('info-box-ti0');
}
//空内容隐藏
if($(this).text() == '' && $(this).find('img').length == 0){
$(this).attr('data-mess','隐藏图片');
$(this).hide();
}
//只有空格隐藏
if($(this).text().match(/^\s+$/)){
$(this).attr('data-mess','隐藏内容');
$(this).hide();
}
})
//去掉图片的样式
$(img).each(function(index,el){
$(this).attr('style','');
$(this).parents('p').addclass('info-box-img');
$(this).parents('p');
})
//显示被误隐藏图片
$('.info-box-img').css('display','block');
//去掉图片附近的回车
$('.info-box-img br').remove();
//去掉文字中带有的空格
$(p+','+span+','+strong).each(function(index,el){
$(this).html($(this).html().replace(/ /ig,''));
$(this).html($(this).html().replace(/\n[\s| | ]*\r/g,''));
})
}