$(function () { /** * 职责链 aop * @param {function} fn */ function.prototype.after = function (nextfn) { var self = this; // object caller prevfn return function () { var result = self.apply(this, arguments); // widnow if (result) { return nextfn.apply(this, arguments); // next } return result; } } /** * 函数节流 * @param {*} func * @param {*} wait * @param {*} immediate * @returns */ function debounce(func, wait, immediate) { var timeout, result; return function () { var context = this, args = arguments; var later = function () { timeout = null; if (!immediate) result = func.apply(context, args); }; var callnow = immediate && !timeout; cleartimeout(timeout); timeout = settimeout(later, wait); if (callnow) result = func.apply(context, args); return result; }; }; /** * 通用 */ (function () { // 导航 $('.mainnav ul li').each(function () { var _secnav = $(this).find('.sec-item'); if (_secnav.length) { $(this).find('.one-title').addclass('hasnav'); } _secnav.each(function () { if ($(this).find('.thr-list a').length) { $(this).find('.sec-title').addclass('hasnav'); } }); }); $('.menu-handle').on('click', function () { $(this).toggleclass('cur'); $('.mainnav ,.sm-fixslide').stop().slidetoggle(); $('.hdr-search').stop().slideup(); }); $('.search-handle ').on('click', function (ev) { ev.stoppropagation(); $('.hdr-search').stop().slidetoggle(); if ($(window).width() < 1024) { $('.menu-handle').removeclass('cur'); $('.mainnav,.sm-fixslide').stop().slideup(); } }); // 底部二维码 $('.ft-wechat').on('click', function (ev) { ev.stoppropagation(); $(this).next().stop().fadein(); $('.ft-sina').next().stop().fadeout(); }); $('.wxpop-close').on('click', function () { $(this).parent().stop().fadeout(); }); $('.ft-sina').on('click', function (ev) { ev.stoppropagation(); $(this).next().stop().fadein(); $(".ft-wechat").next().stop().fadeout(); }); $('.wxpop-close').on('click', function () { $(this).parent().stop().fadeout(); }) // qa $(document).on('click', '.question', function () { if ($(this).next().is(':hidden')) { $(this).addclass('cur').next().stop().slidedown().parent().siblings().find('.question').removeclass('cur').next().stop().slideup();; } else { $(this).removeclass('cur').next().stop().slideup(); } }); // 副导航栏 $('.channel-title ,.third-chl').on('click', function () { $(this).next().stop().slidetoggle(); }); // 产品列表弹窗 $(document).on('click', '.prdt-cate-list li>a', function (ev) { ev.stoppropagation(); $(this).next().stop().show().find('.thumb').stop().show(); }); $(document).on('click', '.data-page-cont li .close', function () { $(this).parents('.prdt-list-popup').stop().hide(); }); // 产品详情 $('.tab-options a').on('click', function () { $(this).addclass('cur').siblings().removeclass('cur'); $('.tab-boxs .tab-item').eq($(this).index()).show().siblings().stop().hide(); }); // document $(document).on('click', function (ev) { if ($(window).width() < 1024) { if (!$(ev.target).closest('.full-inside-subnav').length) { $('.inside-subnav .subnav').stop().slideup(); } if (!$(ev.target).closest('.third-cate').length) { $('.third-cate .cate-list').stop().slideup(); } } if (!$(ev.target).closest('.prdt-list-popup').length) { $('.prdt-list-popup').stop().fadeout(); } if (!$(ev.target).closest('.hdr-search').length) { $('.hdr-search').stop().hide(); } if (!$(ev.target).closest('.qrcode-popup').length) { $('.qrcode-popup').stop().hide(); } }); // 参数前端分页 // 判断头部 // 垂直方向: rowspan.max ; // 判断依据: firsttd.rowspan === maxrowspan || 第一个 tr>td 没有 colspan > 1的 //var singtrindex = (function () { // var maxtr = 5; // var firstrowspan; // var tdrowspanarr = []; // $('.detail-table tr').each(function (index) { // if (index > maxtr) return false; // var tdinner = [], // max, min; // $(this).find('td').each(function (j) { // var _rowspan = $(this).attr('rowspan') || 0; // tdinner.push(parseint(_rowspan)); // tdrowspanarr[index] = tdinner; // }); // max = math.max.apply(math, tdinner); // min = math.min.apply(math, tdinner); // 第一个没有垂直合并的 // console.log(tdrowspanarr); // if (max == min) { // // 多行垂直合并的;=> 头部区域 = index + // firstrowspan = math.max.apply(math, tdrowspanarr[index - 1]) + (index - 1); // 差值 // return false; // } // }); // return firstrowspan; //})(); //console.log("thead结束位置:" + singtrindex); })(); /** * 手机 + pad */ function smevent() { if ($(window).width() < 1024) { console.log('sm'); // header $('.mainnav li').off(); $('.hasnav').off().on('click', function (ev) { // ev.preventdefault(); if ($(this).next().is(':hidden')) { $(this).addclass('roll').next().stop().slidedown().parent().siblings().find('.hasnav').removeclass('.roll').next().stop().slideup(); } else { $(this).removeclass('roll').next().stop().slideup(); } }); // footer $('.ft-nav .channel').off().on('click', function () { var $next = $(this).next(); if ($next.is(':hidden')) { $(this).addclass('cur').next().stop().slidedown().parent().siblings().find('.channel').removeclass('cur').next().stop().slideup(); } else { $next.stop().slideup().prev().removeclass('cur'); } }); } else { return true; } } /** * pc */ function lgevent() { console.log('lg'); // detailt $('.inside-subnav .subnav ,.third-cate .cate-list').show(); $('.hasnav').off(); $('.mainnav li').hover(function () { $(this).find('.one-title').addclass('active').next().show(); }, function () { $(this).find('.one-title').removeclass('active').next().hide(); }); } // get all var mediaevent = smevent.after(lgevent); mediaevent(); // debounce $(window).resize(debounce(mediaevent, 500)); if (typeof swiper != 'undefined') { // 首页 // var ibansw = new swiper('.indexbanner', { // autopaly: 5000, // pagination: '.ipages', // paginationclickable: true // }); // 应用 //var ibansw = new swiper('.apply-swiper', { // pagination: '.apply-pages', // paginationclickable: true, // prevbutton: '.apply-ctrl .prev', // nextbutton: '.apply-ctrl .next', //}); // 产品分类 //var catesw = new swiper('.cate-swiper', { // slidesperview: 6, // spacebetween: 0, // observer: true, // observeparents: true, // prevbutton: '.cate-prev', // nextbutton: '.cate-next', // paginationclickable: true, // initialslide: $('.cate-swiper li.cur').index() || 0, // breakpoints: { // 1023: { // slidesperview: 5, // }, // 767: { // slidesperview: 3, // } // } //}); $(".prdt-cate").each(function (i) { $(this).find(".cate-swiper").addclass("cate-swiper" + i); $(this).find(".cese-btn").addclass("cese-btn" + i); $(this).addclass("prdt-cate" + i); var cetebox = '.cate-swiper' + i; var btn = '.prdt-cate' + i; var caseswiper0 = new swiper(cetebox, { slidesperview: "auto", spacebetween: 0, observer: true, observeparents: true, nextbutton: btn + ' .cate-next', prevbutton: btn + ' .cate-prev', paginationclickable: true, initialslide: $('.cate-swiper li.cur').index() || 0 }); }); // 产品列表 $(".cate-list li").each(function (i) { $(this).find(".prdt-list-popup").addclass("prdt-list-popup" + i); var picturebox = '.prdt-list-popup' + i; var pictureswiper = new swiper(picturebox + ' .prdt-popup-swiper', { slidesperview: 3, spacebetween: 16, observer: true, observeparents: true, nextbutton: picturebox + ' .pop-next', prevbutton: picturebox + ' .pop-prev', paginationclickable: true, breakpoints: { 1023: { slidesperview: 2, }, 767: { slidesperview: 2, } } }); }); // 产品详情 var prdtdetailsw = new swiper('.detail-swiper', { pagination: '.detail-pages', paginationclickable: true, observer: true, observeparents: true }); // 售后服务流程 var salespdfsw = new swiper('.pdf-swiper', { slidesperview: 4, spacebetween: 20, pagination: '.pdf-pages', paginationclickable: true, observer: true, observeparents: true, prevbutton: '.pdf-prev', nextbutton: '.pdf-next', breakpoints: { 1023: { slidesperview: 3, spacebetween: 10 }, 767: { slidesperview: 2, } } }); } }); // footer setstickyfooter($('.footer')); /** * @param {jquerydom} $footer footer的jqdom 默认:$('footer') * @param {jquerydom} $tabsarr 选项卡点击的jq对象 // 其他会影响到文档的高度情况自行添加 */ function setstickyfooter($footer, $tabsarr) { // loaded mutationobserver resize tabclick loadmore refresh var mutationobserver = (function () { // ff14+ ,chrome26+ ,opera15+ , ie11+, safari6.1+ var prefixes = ['webkit', 'moz', 'o', 'ms', '']; for (var i = 0; i < prefixes.length; i++) { if (prefixes[i] + 'mutationobserver' in window) { return window[prefixes[i] + 'mutationobserver']; }; }; return false; }()); // mutationobserver 相关 var target = document.body; var observer; var config = { attributes: true, childlist: true, characterdata: true, subtree: true }; if (mutationobserver) { observer = new mutationobserver(mutationobjectcallback); // callback asyn }; function mutationobjectcallback(mutationrecordslist) { stickyfooter(); }; function stickyfooter() { if (mutationobserver) { observer.disconnect(); }; var footerheight = 0, footertop = 0, $footer = $footer || $("footer"); footerheight = $footer.outerheight(); // height + padding + border footertop = ($(window).scrolltop() + $(window).height() - footerheight) + "px"; if (($(document.body).outerheight()) < $(window).height()) { $footer.css({ visibility: 'visible', position: "absolute", top: footertop }); } else { $footer.css({ visibility: 'visible', position: "static" }); }; //reconnect if (mutationobserver) { observer.observe(target, config); }; } // onload window.onload = function () { stickyfooter(); if (mutationobserver) { observer.observe(target, config); } else { setinterval(stickyfooter, 500); }; }; // resize window.onresize = function () { stickyfooter(); }; // tabclick if (!!$tabsarr) { $tabsarr.click(stickyfooter); }; }; function checkinput(obj) { var pattern = new regexp("[`~!#$^&*()=|{}':;',\\[\\]<>/?~!#¥……&*()——|{}【】‘;:”“'。,、?]") if (pattern.test(obj)) { return false; } return true; } //验证邮箱 function checkmail(mail) { var filter = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/i; if (filter.test(mail)) { return true; } else { return false; } }