/**
* 通用模块
*
*/
var $win = $(window),
$doc = $(document),
$body = $('body', $doc),
winw = $win.width();
$(window).resize(function() {
winw = $win.width();
})
/**
* 图片加载
*/
$(function() {
if (!$.fn.lazyload) return;
$(".lazy", $body).lazyload({
effect: "fadein",
threshold: 200,
failure_limit: 0
});
});
// 出现
$(function() {
if ($win.width() > 992) {
if (!(/msie [6|7|8|9]/i.test(navigator.useragent))) {
new wow().init();
};
}
});
// 数字滚动
// $(function() {
// $('.counter').countup();
// });
// $(function() {
// $(window).on("scroll", function() {
// var t = document.documentelement.scrolltop || document.body.scrolltop; //获取滚动距离
// if (screen.width > 0) {
// if (t >= 100) { //判断
// $(".header").addclass("fixed-header");
// $(".fixed-course").addclass("fopen");
// } else {
// $(".header").removeclass("fixed-header");
// $(".fixed-course").removeclass("fopen");
// }
// }
// })
// });
// 导航固定
$(function() {
var sticky = new waypoint.sticky({
element: $('.top-nav')[0]
});
});
$(function() {
var $biger = $('.wrap-news-show .text');
var num = parsefloat($biger.css('fontsize'));
$('.switcher-bigger').click(function() {
num = num * 1.1;
$biger.css('fontsize', num + 'px');
});
$('.switcher-small').click(function() {
num = num / 1.1;
$biger.css('fontsize', num + 'px');
});
});
// 导航滑动
$(function() {
var jcate = $('.category ul', $body);
var wrap = $('.category');
var wrapwidth = wrap.width();
if (jcate.width() < wrap.width()) {
jcate.width("100%");
} else {
jcate.on('click', 'a', function(event) {
event.preventdefault();
event.stoppropagation();
console.log(this.href);
location.href = this.href;
});
jcate.on('touchstart', function(event) {
jcate.addclass('touchstart');
var touch = event.originalevent.targettouches[0];
var data = {
'touchx': touch.pagex,
'width': jcate.width(),
'left': parseint(jcate.css('left')),
'wwidth': wrapwidth
};
if (data.width < data.wwidth) {
return true;
}
jcate.on('touchmove', data, touchmove);
jcate.on('touchend', touchend);
});
}
// tab 滑动
var touchmove = function(event) {
event.preventdefault();
var touch = event.originalevent.targettouches[0];
var touchx = touch.pagex;
var incr = touchx - event.data.touchx;
var left = event.data.left + incr;
if (left > 0) {
left = 0;
} else if ((event.data.wwidth - left) > event.data.width) {
left = event.data.wwidth - event.data.width;
}
jcate.css('left', left);
};
var touchend = function(event) {
jcate.removeclass('touchstart');
jcate.off('touchmove', touchmove);
jcate.off('touchend', touchend);
};
/**
* init-pos
*/
(function() {
var width = jcate.find('.active').width();
var offset = jcate.find('.active').offset();
var winwidth = $win.width();
var catewidth = jcate.width();
// ($win - jcate) < left < 0
if (offset && catewidth > winwidth) {
var left = winwidth / 2 - (offset.left + width / 2);
left = math.min(left, 0);
left = math.max(left, winwidth - catewidth);
jcate.css('left', left);
}
})();
});
// 视频
$(function() {
var $box = $(".video", $body);
if (!$box.length) return;
$box.on('click', '.video-box .play', function(event) {
event.preventdefault();
var me = $(this);
var $iframe = me.next('.iframe'),
url = $iframe.data('src');
if ($win.width() > 1200) {
$.fancybox.open({
src: url,
type: 'iframe',
padding: 10,
});
} else {
var height = me.find('.img-responsive').length ? me.height() : $box.height();
height = math.max(height, 170);
if (!$iframe.attr('src')) $iframe.attr('src', url);
$iframe.height(height);
$iframe.css('display', 'block');
me.hide();
}
});
});
//头部导航
$(function() {
//折叠导航
var oset;
$(".nav-collapse").click(function(e) {
if (e && e.stoppropagation) {
e.stoppropagation();
} else {
window.event.cancelbubble = true;
}
$(".nav-collapse").toggleclass("active");
$(".nav").stop().fadetoggle().toggleclass("fade-out");
$("body").toggleclass("fixed");
$(".nav").removeclass("left-100 left-200");
if (!$(this).hasclass("active")) {
$(".nav").hide();
$(".nav-list1").find("li").removeclass("act");
} else {
cleartimeout(oset);
$(".nav-list1>li").each(function(index, val) {
var me = $(this);
var num = $(this).index()
oset = settimeout(function() {
me.addclass("act");
}, (index * 100))
})
}
})
});
$(function() {
var list1 = $(".nav-list1"),
list2 = $(".nav-list2"),
list3 = $(".nav-list3");
list1.on("click", ".more", function(event) {
if (winw > 1199) return;
event.stoppropagation();
event.preventdefault();
$(".nav").addclass("left-100");
var ostr = "";
ostr = $(this).children(".nav-list2").html();
ohref = $(this).children("a").clone(true);
$(".nav-2 .content ul").html(ostr).children("li").has(".nav-list3").addclass("more");
$(".nav-2 h2").html(ohref);
})
$(".nav2-list2").on("click", "li", function(event) {
if (winw > 1199) return;
event.stoppropagation();
if ($(this).hasclass("more")) {
event.preventdefault();
$(".nav").addclass("left-200");
var ostr = "";
ostr = $(this).children(".nav-list3").html();
ohref = $(this).children("h4").children("a").clone(true);
console.log($(this).children("h4 a"));
$(".nav-3 .content ul").html(ostr);
$(".nav-3 h2").html(ohref);
}
})
list1.on("mouseenter", ".more", function(event) {
if (winw < 1200) return;
var me2 = $(this).children(".nav-list2");
me2
.stop().slidedown("fast")
.children("li").has(".nav-list3").addclass("more");
}).on("mouseleave", ".more", function(event) {
if (winw < 1200) return;
$(this).children(".nav-list2").stop().slideup("fast");
})
list2.on("mouseenter", "li", function(event) {
if (winw < 1200) return;
console.log($(this).children(".nav-list3"))
$(this).children(".nav-list3").stop().slidedown("fast");
}).on("mouseleave", "li", function(event) {
if (winw < 1200) return;
$(this).children(".nav-list3").stop().slideup("fast");
})
$(".back-btn2").click(function() {
$(".nav").removeclass("left-100");
})
$(".back-btn3").click(function() {
$(".nav").removeclass("left-200");
})
//查找按钮
$(".find").click(function(e) {
if (e && e.stoppropagation) {
//w3c取消冒泡事件
e.stoppropagation();
} else {
//ie取消冒泡事件
window.event.cancelbubble = true;
}
$(".search-lg").stop().fadein();
$(".input-text").focus();
// $("body").addclass('searchactive');
if (winw < 1200) {
$("#btn").removeclass("active");
}
})
$(".search-icon").click(function() {
if (winw < 1200) {
$(".search-xs").addclass("show")
}
})
$(".nav").click(function(e) {
if (!$(e.target).hasclass("input-text") && !$(e.target).hasclass("search-icon")) {
console.log(e.target);
$(".search-xs").removeclass("show")
}
})
$(".close-btn").click(function() {
$(".search-lg").fadeout("fast");
$("body").removeclass('searchactive');
})
});
//首页 banner
$(function() {
if (!$.fn.slick) return;
$('.slickbanner').slick({
autoplay: true,
autoplayspeed: 3000, //以毫秒为单位的自动播放速度
centermode: true, //居中视图 slidestoshow为双数的时候慎用
centerpadding: '0px', //左右两侧padding值
arrows: false, //上一下,下一页
fade: true, //启用淡入淡出
dots: true, //显示点指示符
speed: 500, //幻灯片/淡入淡出动画速度
cssease: 'ease', //css3动画缓和
slidestoshow: 1, //显示的幻灯片数量
slidestoscroll: 1, //要滚动的幻灯片数量
focusonselect: true, //启用选定元素的焦点(单击)
touchthreshold: 300, //滑动切换阈值,即滑动多少像素后切换
infinite: true, //无限循环
swipetoslide: true, //允许用户将幻灯片直接拖动或滑动到幻灯片
lazyload: 'ondemand', //接受'ondemand'或'progressive'
variablewidth: false, //幻灯片宽度自适应
adaptiveheight: false, //自适应高度
rows: 1, //将其设置为1以上将初始化网格模式。使用slidesperrow设置每行应放置多少个幻灯片
slidesperrow: 1, //在通过行选项初始化网格模式时,这会设置每个网格行中的幻灯片数量
});
});
// $(function() {
// var blength = $(".banner .slick-dots li").length;
// $(".to-num").text(blength);
// });
$(function() {
var blength = $(".banner .slick-dots li").length;
$(".to-num").text(blength);
});
$(function() {
if (!$.fn.slick) return;
$('.slick-honor').slick({
autoplay: true,
autoplayspeed: 3000, //以毫秒为单位的自动播放速度
// centermode: true, //居中视图 slidestoshow为双数的时候慎用
centerpadding: '0px', //左右两侧padding值
arrows: false, //上一下,下一页
fade: false, //启用淡入淡出
dots: false, //显示点指示符
speed: 500, //幻灯片/淡入淡出动画速度
cssease: 'ease', //css3动画缓和
slidestoshow: 5, //显示的幻灯片数量
slidestoscroll: 1, //要滚动的幻灯片数量
focusonselect: true, //启用选定元素的焦点(单击)
touchthreshold: 300, //滑动切换阈值,即滑动多少像素后切换
// infinite: true, //无限循环
swipetoslide: true, //允许用户将幻灯片直接拖动或滑动到幻灯片
lazyload: 'ondemand', //接受'ondemand'或'progressive'
variablewidth: false, //幻灯片宽度自适应
adaptiveheight: false, //自适应高度
rows: 1, //将其设置为1以上将初始化网格模式。使用slidesperrow设置每行应放置多少个幻灯片
slidesperrow: 1, //在通过行选项初始化网格模式时,这会设置每个网格行中的幻灯片数量
pauseonhover: false,
responsive: [{
breakpoint: 992,
settings: {
slidestoshow: 4,
slidestoscroll: 1,
}
},
{
breakpoint: 768,
settings: {
slidestoshow: 3,
slidestoscroll: 1,
autoplay: true,
autoplayspeed: 2000,
}
},
{
breakpoint: 480,
settings: {
slidestoshow: 2,
slidestoscroll: 1,
autoplay: true,
autoplayspeed: 2000,
}
}
],
});
});
$('.slick-scientific').owlcarousel({
navigation: true,
navigationtext: false,
pagination: true,
paginationspeed: 400,
slidespeed: 400,
singleitem: false,
items: 3,
itemsdesktopsmall: [1199, 3],
itemstablet: [991, 2],
itemstabletsmall: [480, 1],
itemsmobile: [320, 1],
autoplay: 3000,
autoplay: true,
lazyload: true,
autoheight: false,
stoponhover: false,
rewindnav: true,
// afterinit: function() {
// if ($body.width() < 768) this.stop();
// }
});
//内页滑动导航
$(function() {
var wrap = $(".inside-nav .nav-wrap"),
el_active = wrap.find(".active");
if (!wrap.length || !el_active.length) return;
var active_width = el_active.outerwidth(),
wrap_width = wrap.width(),
act_posi_left = el_active.position().left,
act_width = el_active.outerwidth(),
inline_wrap = el_active.parent(),
inline_width = inline_wrap.outerwidth(true),
distance = (act_posi_left + act_width / 2) - (wrap.outerwidth() / 2);
// if(inline_width <= wrap_width) {
// }
if (distance <= 0) return;
wrap.scrollleft(distance);
});
// $(function() {
// if (!$.fn.slick) return;
// $('.slick-scientific').slick({
// autoplay: true,
// autoplayspeed: 3000, //以毫秒为单位的自动播放速度
// // centermode: true, //居中视图 slidestoshow为双数的时候慎用
// centerpadding: '0px', //左右两侧padding值
// arrows: false, //上一下,下一页
// fade: false, //启用淡入淡出
// dots: false, //显示点指示符
// speed: 500, //幻灯片/淡入淡出动画速度
// cssease: 'ease', //css3动画缓和
// slidestoshow: 3, //显示的幻灯片数量
// slidestoscroll: 1, //要滚动的幻灯片数量
// focusonselect: true, //启用选定元素的焦点(单击)
// touchthreshold: 300, //滑动切换阈值,即滑动多少像素后切换
// // infinite: true, //无限循环
// swipetoslide: true, //允许用户将幻灯片直接拖动或滑动到幻灯片
// lazyload: 'ondemand', //接受'ondemand'或'progressive'
// variablewidth: false, //幻灯片宽度自适应
// adaptiveheight: false, //自适应高度
// rows: 1, //将其设置为1以上将初始化网格模式。使用slidesperrow设置每行应放置多少个幻灯片
// slidesperrow: 1, //在通过行选项初始化网格模式时,这会设置每个网格行中的幻灯片数量
// pauseonhover: false,
// responsive: [{
// breakpoint: 992,
// settings: {
// slidestoshow: 2,
// slidestoscroll: 1,
// }
// },
// {
// breakpoint: 768,
// settings: {
// slidestoshow: 2,
// slidestoscroll: 1,
// autoplay: true,
// autoplayspeed: 2000,
// }
// },
// {
// breakpoint: 480,
// settings: {
// slidestoshow: 1,
// slidestoscroll: 1,
// autoplay: true,
// autoplayspeed: 2000,
// }
// }
// ],
// });
// });
// 浮动客服弹出二维码and缓冲回到顶部
$(function() {
$('.online > .online-wechat').hover(function() {
$('.online-wechat .erweima').stop(true, true).fadein();
}, function() {
$('.online-wechat .erweima').stop(true, true).fadeout();
});
$('.online > .online-weixin').hover(function() {
$('.online-weixin .erweima').stop(true, true).fadein();
}, function() {
$('.online-weixin .erweima').stop(true, true).fadeout();
});
$('.online > .online-tel').hover(function() {
$('.online-tel p').stop(true, true).fadein();
}, function() {
$('.online-tel p').stop(true, true).fadeout();
});
$('.online > .online-whatsapp').hover(function() {
$('.online-whatsapp p').stop(true, true).fadein();
}, function() {
$('.online-whatsapp p').stop(true, true).fadeout();
});
$('#backtop,.backtop').click(function() {
$("html, body").animate({
scrolltop: 0
}, 400);
});
});
$(function() {
$('.icon-online').click(function() {
$('.online').toggleclass('active');
$('.icon-online').toggleclass('icon');
});
});
// 放大
$(function() {
$("a[rel=fancybox-product]").fancybox({
'overlayshow': true,
'overlaycolor': '#000',
'overlayopacity': 0.9,
'opacity': 0.5,
'transitionin': 'elastic',
'transitionout': 'none',
'titleposition': 'over',
'showclosebutton': false,
'titleformat': function(title, currentarray, currentindex, currentopts) {
return '' + (currentindex + 1) + ' / ' + currentarray.length + (title.length ? ' ' + title : '') + ' ';
}
});
});
(function() {
var showmorenchildren = function($children, n) {
//显示某jquery元素下的前n个隐藏的子元素
var $hiddenchildren = $children.filter(":hidden");
var cnt = $hiddenchildren.length;
for (var i = 0; i < n && i < cnt; i++) {
$hiddenchildren.eq(i).show();
}
return cnt - n; //返回还剩余的隐藏子元素的数量
}
//对页中现有的class=showmorehandle的元素,在之后添加显示更多条,并绑定点击行为
$(".showmorenchildren").each(function() {
var pagesize = $(this).attr("pagesize") || 12;
var $children = $(this).children();
if ($children.length > pagesize) {
for (var i = pagesize; i < $children.length; i++) {
$children.eq(i).hide();
}
$("