$(document).ready(function($) {
// 导航
// PC二级导航
$(".nav li").on('mouseenter', function() {
$(this).find(".two-level").stop().slideDown();
$(this).find(".two-level2").stop().slideDown();
})
$(".nav li").on('mouseleave', function() {
$(this).find(".two-level").stop().slideUp();
$(this).find(".two-level2").stop().slideUp();
})
// PC二级导航 end
//产品二级导航优化
$(".product-nav-pc dl").each(function(index){
if($(this).find("dd").length<5){
for(var i=0; i<5-$(this).find("dd").length; i++){
$(this).append("
");
}
}
});
// 手机端导航
$(".menuBtn").click(function() {
$(".nav").toggleClass("open");
$(this).toggleClass("open")
$('.mark-bg').stop().fadeToggle();
$(".header").toggleClass("white trs inner")
})
var _width = $(document).innerWidth();
if (_width < 1024) {
$(".nav li").off("mouseenter mouseleave");
$(".nav li.level>a").attr("href", "javascript:;")
$(".nav li.level>a").click(function() {
$(this).toggleClass("active").parents("li").siblings("li").find("a").removeClass("active");
$(this).parents("li").siblings("li").find("a").siblings(".two-level").slideUp();
$(this).parents("li").siblings("li").find("a").siblings(".two-level2").slideUp();
$(this).siblings(".two-level").stop().slideToggle();
$(this).siblings(".two-level2").stop().slideToggle();
})
$(".fd-link dt").click(function() {
$(this).toggleClass("active").siblings("dd").stop().slideToggle();
})
$(window).scroll(function() {
var _top = $(window).scrollTop();
if (_top < 100) {
$('.header').removeClass("trs");
} else {
$('.header').addClass("trs");
}
});
$(".mo-so1").click(function() {
$(".hd-search").show()
$(".mo-hotSearch").toggleClass("show")
})
$(".hd-search .close").click(function() {
$(".hd-search").hide()
$(".mo-hotSearch").removeClass("show")
})
}
$(window).resize(function() {
$('.mark-bg').stop().hide();
var _width = $(document).innerWidth();
if (_width < 960) {
$('.nav').removeClass("open");
$('.menuBtn').removeClass("open");
}
})
// 弹出框
$('.myfancy').click(function() {
var _id = $(this).attr('href');
$(_id).find(".pop-bg").stop().fadeIn();
$(_id).stop().fadeIn();
});
$('.pop-bg,.close').click(function() {
$(this).parents('.m-pop').stop().fadeOut();
$(".pop-bg").stop().fadeOut();
});
// 选项卡 鼠标点击切换
$(".TAB_CLICK li").click(function() {
var tab = $(this).parent(".TAB_CLICK");
var con = tab.attr("id");
var on = tab.find("li").index(this);
$(this).addClass('on').siblings(tab.find("li")).removeClass('on');
$(con).eq(on).show().siblings(con).hide();
});
// 选项卡 鼠标经过切换
$(".TAB li").mousemove(function() {
var tab = $(this).parent(".TAB");
var con = tab.attr("id");
var on = tab.find("li").index(this);
$(this).addClass('hover').siblings(tab.find("li")).removeClass('hover');
$(con).eq(on).show().siblings(con).hide();
});
//返回顶部
$('.goTop').click(function() {
$('body,html').animate({
'scrollTop': 0
}, 500);
});
$(window).scroll(function() {
var _top = $(window).scrollTop();
if (_top < 100) {
$('.goTop').stop().fadeOut(500);
} else {
$('.goTop').stop().fadeIn(500);
}
});
//头部背景
headbg();
setTimeout("headbg()", 500);
$(window).scroll(function() {
headbg();
});
//外链
$(".nav a,.fd-link a,.base-nav a").each(function(){
if($(this).attr("href") && $(this).attr("href").indexOf("//")>-1){
$(this).attr("target", "_blank");
}
});
//先将#back-top隐藏
$('#back-top').hide();
//当滚动条的垂直位置距顶部100像素一下时,跳转链接出现,否则消失
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('#back-top').fadeIn(1000);
} else {
$("#back-top").fadeOut(1000);
}
});
//点击跳转链接,滚动条跳到0的位置,页面移动速度是1000
$("#back-top").on("click", function(){
$("html,body").animate({
scrollTop: '0'
}, 500);
return false; //防止默认事件行为
});
//禁用右键、文本选择功能、复制按键
$(document).bind("contextmenu",function(){return false;});
//$(document).bind("selectstart",function(){return false;});
//$("img").on("contextmenu",function(){return false;});
$("img").on("dragstart",function(){return false;});
/*if($(window).width()<1024){
alert(
"屏幕尺寸:" + screen.width + "*" + screen.height + "\n" +
"窗口尺寸:" + $(window).width() + "*" + $(window).height() + "\n" +
"文档尺寸:" + $(document).width() + "*" + $(document).height()
);
}*/
//记录浏览器屏幕
//$.post("/api/navigator", {screenWidth: screen.width, screenHeight: screen.height, windowWidth: $(window).width(), windowHeight: $(window).height(), appName: navigator.appName, userAgent: navigator.userAgent});
(function() {
// 自定义多选
$('[role=checkbox]').each(function() {
var input = $(this).find('input[type="checkbox"]');
input.each(function() {
if ($(this).attr('checked')) {
$(this).parents('label').addClass('checked');
$(this).prop("checked", true)
}
})
input.change(function() {
$(this).parents('label').toggleClass('checked');
});
})
})();
(function() {
// 自定义单选
$('[role=radio]').each(function() {
var input = $(this).find('input[type="radio"]'),
label = $(this).find('label');
input.each(function() {
if ($(this).attr('checked')) {
$(this).parents('label').addClass('checked');
$(this).prop("checked", true)
}
})
input.change(function() {
label.removeClass('checked');
$(this).parents('label').addClass('checked');
input.removeAttr('checked');
$(this).prop("checked", true)
})
})
})();
});
//头部背景
function headbg(){
if($("body").is(".full") == false){
var _top = $(window).scrollTop();
if (_top < 50) {
$('.header').removeClass("white");
} else {
$('.header').addClass("white");
}
}
}