/*防抖动函数*/ function debounce(func,delay,immediate){ var timer = null; return function(){ var context = this; var args = arguments; if(timer) cleartimeout(timer); if(immediate){ //根据距离上次触发操作的时间是否到达delay来决定是否要现在执行函数 var donow = !timer; //每一次都重新设置timer,就是要保证每一次执行的至少delay秒后才可以执行 timer = settimeout(function(){ timer = null; },delay); //立即执行 if(donow){ func.apply(context,args); } }else{ timer = settimeout(function(){ func.apply(context,args); },delay); } } } $(function(){ /*文字动画初始化*/ /*pc 导航展开*/ var _headerli=$('.menue-header .menue-nav li'); var ease_1=customease.create("custom", "m0,0 c0.596,0.492 0.01,0.98 1,1"); tweenmax.set($('.hide',_headerli), { scaley: '0', autoalpha: 0 }); tweenmax.set($('.hide .sub-link',_headerli), { y: '-10px', autoalpha: 0 }); var pcheader=''; _headerli.hover(function(){ var _this=$(this); var $box=$('.hide',_this); tweenmax.to($('.link .icon',_this),0.4,{ rotationz: 180 }); tweenmax.to($box, 0.8, { scaley: '1', autoalpha: 1, ease: ease_1, onstart: function(){ _this.addclass('nohover'); }, oncomplete: function(){ } }); tweenmax.to($('.hide .sub-link',_this), 0.4, { y: '0px', autoalpha: 1, delay: 0.4, oncomplete: function(){ _this.removeclass('nohover'); } }); },function(){ // cleartimeout(pcheader); tweenmax.to($('.link .icon',_headerli),0.4,{ rotationz: 0 }); tweenmax.to($('.hide .sub-link',_headerli), 0.4, { y: '-10px', autoalpha: 0, oncomplete: function(){ } }); tweenmax.to($('.hide',_headerli), 0.8, { scaley: '0', autoalpha: 0, ease: ease_1, oncomplete: function(){ _headerli.removeclass('nohover'); } }); }); /*m 导航展开*/ var _mheader=$('.menue-header-m'); /*一级*/ $('.menue-menu',_mheader).click(function(){ if(!_mheader.hasclass('ishow')){ _mheader.addclass('ishow'); }else{ _mheader.removeclass('ishow'); $('.menue-nav li .hide',_mheader).removeclass('ishow'); } }); $('.bg',_mheader).click(function(){ _mheader.removeclass('ishow'); $('.menue-nav li .hide',_mheader).removeclass('ishow'); }); /*二级*/ $('.menue-nav li .link',_mheader).click(function(){ var _that=$(this).parent().find('.hide'); if(_that.length>0){ _that.addclass('ishow'); } }); $('.menue-nav .title.sub-link .back',_mheader).click(function(){ var _that=$(this).parents('.hide'); _that.removeclass('ishow'); }); $('.menue-header-m .menue-nav li.wechat .link').click(function(){ if($('.m-qr-box .qr-bg').is(':hidden')){ $('.m-qr-box .qr-bg, .m-qr-box .img-box').stop().fadein(800); }else{ $('.m-qr-box .qr-bg, .m-qr-box .img-box').stop().fadeout(800); } }); $('.m-qr-box .qr-bg').click(function(){ $('.m-qr-box .qr-bg, .m-qr-box .img-box').stop().fadeout(800); }); }); var startx, starty; //手指接触屏幕 document.addeventlistener("touchstart", function(e) { // e.preventdefault(); startx = e.touches[0].pagex; starty = e.touches[0].pagey; }, false); //手指离开屏幕 document.addeventlistener("touchend", function(e) { // e.preventdefault(); var endx, endy; endx = e.changedtouches[0].pagex; endy = e.changedtouches[0].pagey; var direction = getdirection(startx, starty, endx, endy); // alert(direction) if(direction==4&&$('.menue-header-m').hasclass('ishow')){ $('.menue-header-m').removeclass('ishow'); $('.menue-nav li .hide',$('.menue-header-m')).removeclass('ishow'); } }, false); /*获得角度*/ function getangle(angx, angy) { return math.atan2(angy, angx) * 180 / math.pi; }; /*根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动*/ function getdirection(startx, starty, endx, endy) { var angx = endx - startx; var angy = endy - starty; var result = 0; //如果滑动距离太短 if (math.abs(angx) < 2 && math.abs(angy) < 2) { return result; } var angle = getangle(angx, angy); if (angle >= -45 && angle <= 45) { result = 4; } return result; }