function stopBubble(e) { // 如果传入了事件对象,是非ie浏览器 if (e && e.stopPropagation) { //因此支持W3C的stopPropagation()方法 e.stopPropagation(); } else { //否则用ie的方法来取消事件冒泡 window.event.cancelBubble = true; } } //回到顶部 var backButton=$('.back-to-top'); function backToTop() { $('html,body').animate({ scrollTop: 0 }, 500); } backButton.on('click', backToTop); $(window).on('scroll', function () { if ($(window).scrollTop() > 300) backButton.fadeIn(); else backButton.fadeOut(); }); $(window).trigger('scroll');/*触发滚动事件,避免刷新的时候显示回到顶部按钮*/ //顶部导航开始 $('.tab-img li').hover(function () { var index = $(this).index(); $(this).addClass("on").siblings().removeClass("on"); $(this).parents(".tab-img").siblings().find(".item").eq(index).addClass("on").siblings().removeClass("on"); }); $('.tab-product dd').mouseenter(function () { var thisNum = $(this).attr('data-num'); $(this).parents(".left").siblings('.right').find('.items[data-num="' + thisNum + '"]').show(); }).mouseleave(function () { var thisNum = $(this).attr('data-num'); $(this).parents(".left").siblings('.right').find('.items[data-num="' + thisNum + '"]').hide(); }); $('.header-box .search-btn span').click(function (e){ var hs = $(".search-box"); if(hs.is(":visible")) { $(".search-box").hide(); }else{ $(".search-box").show(); } stopBubble(e) }); $(document).click(function () { $(".search-box").hide(); }); $(".search-box").click(function (e) { stopBubble(e); }); //顶部导航结束 //底部更多与隐藏的点击事件 var more = $(".footer-box .ft-nav:last-child ul li:gt(4)"); var last = $(".footer-box .ft-nav:last-child ul li:last-child"); more.hide(); last.show(); last.click(function (){ more.show(); last.hide(); }); //滚动透明导航条 // var nav = $(".header-box"); //得到导航对象 // var win = $(window); //得到窗口对象 // var sc = $(document); //得到document文档对象。 // win.scroll(function() { // if (sc.scrollTop() >= 50) { // nav.addClass("fixednav"); // } else { // nav.removeClass("fixednav"); // } // }) //pc判断上下滑动 function pc() { $(document).ready(function() { var p = 0, t = 0; $(window).scroll(function() { p = $(this).scrollTop(); if (t <= p) { //下滚 $(".header-box").stop(true, true).addClass("on1"); } else { //上滚 $(".header-box").stop(true, true).removeClass("on1"); } setTimeout(function() { t = p; }, 0); }); }) } //手机判断上下滑动 function ph() { $('body').bind('touchstart', function(e) { startX = e.originalEvent.changedTouches[0].pageX; startY = e.originalEvent.changedTouches[0].pageY; }); $("body").bind("touchmove", function(e) { //获取滑动屏幕时的X,Y endX = e.originalEvent.changedTouches[0].pageX; endY = e.originalEvent.changedTouches[0].pageY; //获取滑动距离 distanceX = endX - startX; distanceY = endY - startY; //判断滑动方向 if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 0) { //alert('往右滑动'); } else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < 0) { //alert('往左滑动'); } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < 0) { $(".header-box").stop(true, true).addClass("on1"); } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 0) { $(".header-box").stop(true, true).removeClass("on1"); } }) } //pc和手机方法调用判断 $(function() { var system = { win: false, mac: false, xll: false, ipad: false }; //检测平台 var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac = p.indexOf("Mac") == 0; system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); system.ipad = (navigator.userAgent.match(/iPad/i) != null) ? true : false; // if (system.win || system.mac || system.xll || system.ipad) { // pc(); // } else { // ph(); // } }) //右侧客服 $(".online-box .left").click(function () { $(".online-box").animate({right:"0"},300); }); $(".online-close").click(function () { $(".online-box").animate({right:"-128px"},300); }); $(document).click(function () { $(".online-box").animate({right:"-128px"},300); }); $(".online-box").click(function (e) { stopBubble(e); });