/*引入页首、页脚*/ /*$.ajax({ url: 'header.html', async: false, success: function(res){ $('#header').prop('outerhtml', res); } }); $.ajax({ url: 'footer.html', async: false, success: function(res){ $('#footer').prop('outerhtml', res); } }); /*显示、隐藏导航子菜单*/ (function( $nav ){ var $subnav = $('#subnav'); var $subitem = $('.sub-nav-item'); var isshow = false; var timeout = null; $nav.add($subnav).hover(function(){ if( $(window).width() < 1200 ) return; var $this = $(this); cleartimeout(timeout); if( ($this.is('li') && $this.attr('target')) || $this.is( $subnav ) ){ if( $this.attr('target') ){ $subitem.hide(); console.log($('#'+$(this).attr('target')).height()); $('#'+$(this).attr('target')).show(); } if( !isshow ){ $subnav.stop().slidedown(300); isshow=true }else{ $subnav.height('auto').show(); } }else{ $subnav.stop().slideup(200, function(){ isshow = false; }); } }, function(){ timeout = settimeout( function(){ $subnav.stop().slideup(200, function(){ isshow = false; }); }, 100 ); }); })($('nav ul li')); /*页首导航切换变色*/ /*(function(){ var url = location.href; var $nav = $('#slidetoggletrans li'); $nav.eq(0).addclass('active').end().not(":first-child").each( function(){ var href = $(this).find('a').prop('href'); if( url.indexof( href ) > -1 ){ $(this).addclass('active').siblings().removeclass('active'); return false; } } ); })();*/ /*下拉、收起*/ var slidetoggletrans = function(element, display) { // display表示默认更多展开元素是显示状态还是隐藏 if (typeof window.screenx === "number") { // 现代浏览器 element.addeventlistener("click", function() { display = !display; var rel = this.getattribute("data-rel"), elemore = document.queryselector("#" + rel); elemore && (elemore.style.height = display? (function() { var height = 0; array.prototype.slice.call(elemore.childnodes).foreach(function(child) { if (child.nodetype === 1) { var ostyle = window.getcomputedstyle(child); height = child.clientheight + (parseint(ostyle.bordertopwidth) || 0) + (parseint(ostyle.borderbottomwidth) || 0); } }); return height; })() + "px": "0px"); }); } else { // ie6-ie8浏览器 element.attachevent("onclick", function() { display = !display; var rel = element.getattribute("data-rel"), elemore = document.getelementbyid(rel); elemore && (elemore.style.height = display? "auto": "0px"); return false; }); } }; /*低分辨率下 页首 展示收起导航*/ (function( $navtogglebtn ){ if( !$navtogglebtn[0] ) return; var $nav = $('#nav'); $navtogglebtn.on('click', function(){ var $this = $(this); $this.toggleclass('active'); $nav[ $this.hasclass('active') ? 'addclass' : 'removeclass' ]('active'); }); slidetoggletrans($navtogglebtn[0]); })( $('#navtogglebtn') ); /*切换标签和内容*/ (function( $swipertagwrapper ){ if( !$swipertagwrapper[0] ) return; var target = $swipertagwrapper.data('rel'); var $swipertab = $swipertagwrapper.find('.swiper-tab'); var tabswiper = new swiper(target, { paginationclickable: true, autoplaydisableoninteraction: false, onslidechangeend: function(swiper){ $swipertab.eq( swiper.activeindex ).addclass('active').siblings().removeclass('active'); } }); $swipertab.on('click', function(){ tabswiper.swipeto( $(this).index(), $swipertagwrapper.data('speed') || 10 ); }); })( $('.swpier-tab-wrapper') ); /*返回顶部按钮*/ var $top = $('.to-top'); (function(){ var timeout = null; $(window).on('scroll', function(){ var $this = $(this); if( timeout ) return; timeout = settimeout( function(){ var width = $this.width(); var right = 30; if( width > 1300 ){ right = (width - 1200)/2 - 20 - 48; } if( $this.scrolltop() > 600 ){ if( $top[0] ){ $top.show(); }else{ $top= $(''); $('body').append($top); } }else{ $top[0] && $top.hide(); } $top.css('right', right); timeout = null; }, 60 ); }); $(document).on('click', '.to-top', function(){ $('html, body').scrolltop(0); }); })(); /*鼠标移到列表,显示更多信息(比如图片,描述等)*/ (function( $tabitem ){ if( !$tabitem[0] ) return; $tabitem.hover(function(){ $(this).addclass('active').siblings().removeclass('active'); }, function(){}); })( $('.tab-item') ); /*分页*/ (function( elem ){ if( !elem[0] ) return; var url = elem.attr('url'), cur = number(elem.data('page')), //当前页码 total = number(elem.data('total')), //总页码 view = number( total > 5 ? 5 : total ), //每次展示的页码数 min = 1, //当前展示的最小页码 max = total, //当前展示的最大页码 half = math.ceil(view/2), str = ''; var width = $(window).width(); if( total > view ){ if( cur <= half ){ min = 1; max = min + view-1; }else if( cur > half && cur < total - half + 1 ){ min = cur - half + 1; max = cur + half-1; }else{ min = total - (view - 1); max = total; } } str += cur == 1 ? '上一页' : '' //pc端 if( width >= 768 ){ str += cur > half && total > view ? '...' : ''; for(var i = 0; i < view; i++){ if( cur == min + i ) str += ''+(min+i)+'' else str += ''+(min+i)+''; } str += cur < total - half + 1 && total > view ? '...' : ''; //移动端 }else{ str += ''; } str += cur == total ? '下一页' : ''; elem.prepend( str ); elem.find('select').on('change', function(){ location.href = url + $(this).val(); }); })( $('#pagebox') );