var isMobile = false,
mobile = false,
isShow = false,
win_width = 0,
win_height = 0,
atH = 0,
pnavH=0,
navItem=0,
$menuBtn = $('.menu-handler');
var pageInit = {
init: function () {
pageInit.getCommon();
nav.init();
menu.init();
pageInit.inview();
pageInit.videoShow();
},
inview:function(){
$('.target').on('inview', function() {
$(this).addClass('action');
});
},
getCommon: function () {
function wh() {
win_width = ('innerWidth' in window) ? window.innerWidth : document.documentElement.clientWidth;
win_height = ('innerHeight' in window) ? window.innerHeight : document.documentElement.clientHeight;
atH = $(".pageH").innerHeight();
if (win_width <= 1180) {
isMobile = true;
} else if (win_width > 1180) {
isMobile = false;
};
if (win_width <= 640) {
mobile = true;
} else if (win_width > 640) {
mobile = false;
};
};
wh();
$(window).on("resize",function () {
wh();
});
},
setImgMax: function (img, imgW, imgH, tW, tH) {
var tWidth = tW || win_width;
var tHeight = tH || win_height;
var coe = imgH / imgW;
var coe2 = tHeight / tWidth;
if (coe < coe2) {
var imgWidth = tHeight / coe;
img.css({
height: tHeight,
width: imgWidth,
left: -(imgWidth - tWidth) / 2,
top: 0
});
} else {
var imgHeight = tWidth * coe;
img.css({
height: imgHeight,
width: tWidth,
left: 0,
top: -(imgHeight - tHeight) / 2
});
};
},
getUrlParam:function (paramName) {
var arrObj = window.location.href.split("?");
if (arrObj.length > 1) {
var arrPara = arrObj[1].split("&");
var arr;
for (var i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("=");
if (arr != null && arr[0] == paramName) {
return arr[1];
}
}
return null;
}
else {
return null;
}
},
setScroll: function (anchorCur,speed,antype) {
if ($(anchorCur).length >= 1) {
$("html,body").animate({
scrollTop: $(anchorCur).offset().top -(atH+pnavH)
}, speed,antype);
}
},
setErmbox: function (obj) {
var str,txt="扫描此二维码关注我们";
if(obj.attr("data-txt")!=undefined || obj.attr("data-txt") !=null){
str = '
' + obj.attr("data-txt") + '
';
}else{
str = '';
}
$("body").append(str);
$(".ermsblack").stop(false, false).fadeIn();
$(".ermSBox").stop(false, false).animate({
top: "50%"
}, 400);
$(".ermSBox .form-box-close").on('click',function () {
$(".ermsblack").remove();
});
$(".ermsblack").on('click',function () {
$(".ermsblack").remove();
});
return false;
},
tabSwiper:function(navigation,mySwiper,morelink) {
var slides = mySwiper.slides,
item = navigation,
itemActive = item.eq(0),
moreL;
if(morelink!==""){
moreL=morelink;
moreL.attr("href",item.eq(0).data("mlink"));
};
item.eq(0).addClass("active");
item.on('click', function () {
if(morelink!==""){
moreL.attr("href",$(this).data("mlink"));
};
item.removeClass("active");
$(mySwiper.el).removeClass("active");
$(this).addClass("active");
itemActive = $(this);
updateSliders();
});
var updateSliders = function(){
var arr = Array.prototype.slice.call(slides).filter(function (slides) {
if(itemActive.data("name")=="all"){
return slides;
}else{
return slides.getAttribute('data-name') == itemActive.data("name");
}
});
mySwiper.removeAllSlides();
for (var i = 0; i < arr.length; i++) {
mySwiper.appendSlide(arr[i]);
};
setTimeout(function(){
$(mySwiper.el).addClass("active");
},0);
};
updateSliders();
},
tabSwiper2:function(navigation,mySwiper,speed) {
var itemActive=0,
item = navigation;
item.eq(0).addClass("active");
item.on('click', function () {
item.removeClass("active");
$(this).addClass("active");
itemActive = $(this).index();
mySwiper.slideTo(itemActive, speed, true);
setTimeout(function(){
$(mySwiper.el).addClass("active");
},0);
});
mySwiper.on('slideChangeTransitionStart', function(e) {
navigation.eq(this.activeIndex).addClass('active').siblings().removeClass('active');
$(mySwiper.el).removeClass("active");
});
},
splitWords: function (el) {
var _test = el.html().split('
');
el.html('');
for (var i = 0; i < _test.length; i++) {
el.append('
');
_test[i] = _test[i].split('');
var _span = el.find('span');
for (var j = 0; j < _test[i].length; j++) {
_span.eq(i).append('');
var _i = _span.eq(i).find('i');
if (_test[i][j] === ' ') {
_test[i][j] = ' '
}
_i.eq(j).html(_test[i][j])
}
}
},
setWordsDelay: function (el, time, delay, reverse) {
var _span = el.find('span');
_span.each(function (i) {
var _i = $(this).find('i');
var random = 1;
_i.each(function (j) {
if (reverse) {
j = _i.length - j - 1;
}
random = Math.random();
$(this).css({
'animation-delay': delay + time * random + 'ms',
'-webkit-animation-delay': delay + time * random + 'ms'
})
})
})
},
setSplit: function (el) {
var n = el;
for (var e = 0, t = n.length; e < t; e++) {
var a = n[e],
r = a.textContent.trim();
a.innerHTML = "";
i(a, r)
}
function i(n, e) {
for (var t in e) {
var a = document.createElement("span");
a.innerHTML = e[t] === " " ? " " : e[t];
n.appendChild(a);
}
}
},
setTimeDelay: function (el, time, delay, reverse) {
var _span = el;
_span.each(function (i) {
var _i = $(this).find('span');
var random = 1;
_i.each(function (j) {
if (reverse) {
j = _i.length - j - 1;
}
random = Math.random();
$(this).css({
'animation-delay': delay + time * random + 'ms',
'-webkit-animation-delay': delay + time * random + 'ms'
})
})
})
},
setround: function (el) {
var _span = el;
_span.each(function (i) {
var _i = $(this).find('span');
var arr=$(this).attr("data-num").split(',');
for(var i in arr){
_i.eq(arr[i]-1).addClass("gree");
}
})
},
setround2: function (el) {
var _span = el;
_span.each(function (i) {
var _i = $(this).find('span');
var k1 = Math.round(Math.random() * 5);
var k2 = Math.round(Math.random() * 10);
_i.eq(k1).addClass("cor");
_i.eq(k2).addClass("cor");
})
},
setSplitshun: function(el) {
var n = el;
for (var e = 0, t = n.length; e < t; e++) {
var a = n[e],
r = a.textContent.trim();
a.innerHTML = "";
i(a, r)
}
function i(n, e) {
for (var t in e) {
var a = document.createElement("span");
a.innerHTML = e[t] === " " ? " " : e[t];
n.appendChild(a);
}
}
},
setTimeDelayshun: function(el, time, delay, reverse) {
var _span = el;
_span.each(function(i) {
var _i = $(this).find('span');
_i.each(function(j) {
if (reverse) {
j = _i.length - j - 1;
}
$(this).css({
'animation-delay': delay + time * j + 'ms',
'-webkit-animation-delay': delay + time * j + 'ms'
})
})
})
},
showbox: function (htmlAddress) {
$.ajax({
url: htmlAddress,
dataType: "html",
success: function (data) {
if (data == "" || data == null) {
return;
}
else {
if (jQuery(".md-modal").length >= 1) {
lenis.start();
jQuery('html').removeClass('md-show');
jQuery('.md-modal').remove();
};
$("body").append('');
$('.md-modal .md-modal-page').append(data);
setTimeout(function () { $("html").addClass("md-show"); }, 50);
jQuery('.form-box-close').on('click', function (e) {
jQuery('html').removeClass('md-show');
lenis.start();
setTimeout(function () { jQuery('.md-modal').remove(); }, 400);
});
jQuery('.md-modal .md-modal-page').on('click', function (e) {
if ($(e.target).hasClass('md-modal-page')) {
jQuery('html').removeClass('md-show');
lenis.start();
setTimeout(function () { jQuery('.md-modal').remove();}, 400);
}
});
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
jQuery('html').removeClass('md-show');
lenis.start();
setTimeout(function () { jQuery('.md-modal').remove();}, 400);
}
});
},
videoShow: function () {
$(".video-sbtn").on("click",function() {
var videoName = $(this).data('url');
$(".videon").attr("src", videoName);
$(".pvideo-bg").addClass("overlay");
});
$(".pv-close").on("click",function() {
$(".pvideo-bg").removeClass("overlay");
$(".videon").attr("src", "");
});
$(".vwrap .close,.vwrap .videobtg").on("click",function() {
$(".vwrap").hide();
$('#videobox').html("");
});
}
},
nav = {
init: function () {
$(".nav li").hover(function () {
$(this).children("a").addClass("hov");
}, function () {
$(this).children("a").removeClass("hov");
});
$(document).on("click", ".nav .subnav a", function(e) {
var $this = jQuery(this);
var hash = $this.attr("href").split("#")[1];
if (hash) {
e.preventDefault();
pageInit.setScroll("#" + hash, 600,'easeInOutExpo');
}
});
$('.link-select-box').on("click",function() {
if ($(this).hasClass('act')) {
$(this).removeClass('act');
$(this).find('.mc').stop().slideUp(300);
} else {
$(this).addClass('act');
$(this).find('.mc').stop().slideDown(300);
}
}).on("mouseleave",function(){
$(this).removeClass('act');
$(this).find('.mc').stop().slideUp(300);
});
$(".cq-serach,.top-grop-serach").on("click",function() {
$(".cq-serach-layer").addClass("cq-serach-show");
});
$(".cq-serach-close").on("click",function() {
$(".cq-serach-layer").removeClass("cq-serach-show");
});
}
},
menu={
init: function () {
$menuBtn.on("click",function() {
if (navItem == 0) {
$(this).addClass("active");
$("html").addClass("menu-open");
navItem = 1;
} else {
$(this).removeClass("active");
$("html").removeClass("menu-open");
navItem = 0;
}
});
$(document).on("click", ".menubarM-list a", function(e) {
var $this = jQuery(this);
var hash = $this.attr("href").split("#")[1];
if (hash) {
e.preventDefault();
pageInit.setScroll("#" + hash,600,'easeInOutExpo');
menu.close();
}
});
$(document).on("click", ".menubarM-list>li>a", function(e) {
var mnavli = $(this).parents("li");
var mnavsub = mnavli.find(".subnav");
if (mnavsub.length > 0) {
e.preventDefault();
if (mnavli.hasClass("cur")) {
mnavli.removeClass("cur");
mnavsub.stop(false, false).slideUp();
} else {
mnavli.addClass("cur").siblings().removeClass("cur");
$(".menubarM-list .subnav").stop(false, false).slideUp();
mnavsub.stop(false, false).slideDown();
e.preventDefault();
}
}
});
$(".pusher-black").on("click",function(){
menu.close();
});
},
close: function() {
$menuBtn.removeClass("active");
$("html").removeClass("menu-open");
navItem = 0;
}
};
pageInit.init();
// $("img.lazy").lazyload();
$(window).on("load",function(){
var hash = location.href.split("#")[1];
if (hash) {
pageInit.setScroll("#" + hash,0,'');
}
});