$(function(){ //点击图标出现导航栏 pc function navpc(){ $("#moblie_nav").unbind().click(function(){ $("#moblie_nav_wrap").css("left","768px").animate({"left":"0px"},500).show(); }); $('.moblie_open').unbind().click(function(){ $("#moblie_nav_wrap").css("left","0").animate({"left":"768px"},500); }); $('#moblie_nav_wrap >ul > li').each(function(){ if ($( this).children('dl').length==0) { $(this).find('i').hide(); } else { $(this).find('i').show(); $(this).children('a').attr('href','javascript:;') } }); var b=1; $('#moblie_nav_wrap >ul > li').click(function(){ if(b=='1'){ var dl_h=parseint($(this).children('dl').css('height'))+25; $(this).children('dl').show(); $(this).css('height',''+dl_h+'px'); $(this).find('i').css('background-position','-8px -3px'); b=0; }else{ $(this).children('dl').hide(); $(this).css('height','33px'); $(this).find('i').css('background-position','0px 0px'); b=1; } }); } //点击图标出现导航栏 移动端 function andriodnav(){ $("#moblie_nav").on('touchstart',function() { $("#moblie_nav_wrap").css("left","768px").animate({"left":"0px"},500).show(); }); $('.moblie_open').on('touchstart',function() { $("#moblie_nav_wrap").css("left","0").animate({"left":"768px"},500); }); $('#moblie_nav_wrap >ul > li').each(function(){ if ($( this).children('dl').length==0) { $(this).find('i').hide(); } else { $(this).find('i').show(); $(this).children('a').attr('href','javascript:;') } }); var b=1; $('#moblie_nav_wrap >ul > li').on('touchstart',function() { if(b=='1'){ var dl_h=parseint($(this).children('dl').css('height'))+25; $(this).children('dl').show(); $(this).css('height',''+dl_h+'px'); $(this).find('i').css('background-position','-8px -3px'); b=0; }else{ $(this).children('dl').hide(); $(this).css('height','33px'); $(this).find('i').css('background-position','0px 0px'); b=1; } }); } //pc的clearfix function pcclearfix(){ var speed=20//速度数值越大速度越慢 var colee_left2=document.getelementbyid("colee_left2"); var colee_left1=document.getelementbyid("colee_left1"); var colee_left=document.getelementbyid("colee_left"); if(colee_left1){ colee_left2.innerhtml=colee_left1.innerhtml var mymar3=setinterval(marquee3,speed) colee_left.onmouseover=function() {clearinterval(mymar3)} colee_left.onmouseout=function() {mymar3=setinterval(marquee3,speed)} } function marquee3(){ if(colee_left2.offsetwidth-colee_left.scrollleft<=0)//offsetwidth 是对象的可见宽度 colee_left.scrollleft-=colee_left1.offsetwidth//scrollwidth 是对象的实际内容的宽,不包边线宽度 else{ colee_left.scrollleft++ } } } function fenlei(){ var fr_li=$('.clearfix li ').last().index(); var li_w=$('.clearfix li ').width(); var top=(li_w-2)*fr_li var start=0; var rhui = window.rhui || {}; window.rhui = rhui; rhui.mobile = (function(){ var touch = { distance: 10, //滑动距离,超过该距离触发swipe事件,单位像素。 duration: 1000 //滑动时长,超过该时间不触发swipe,单位毫秒。 }; function bindswipe(el, swipe, callback, triggeronmove, isstoppropagation, ispreventdefault){ var startpoint, endpoint, timer; function swipedirection(x1, y1, x2, y2){ var diffx = x1 - x2, diffy = y1 - y2, absx = math.abs(diffx), absy = math.abs(diffy), swipe; if(absx >= absy){ if(absx >= touch.distance){ swipe = diffx > 0 ? 'swipeleft' : 'swiperight'; } }else{ if(absy >= touch.distance){ swipe = diffy > 0 ? 'swipeup' : 'swipedown'; } } return swipe; } // 清除本次滑动数据 function clearswipe(){ startpoint = undefined; endpoint = undefined; if(timer !== undefined){ cleartimeout(timer); timer = undefined; } } function execswipe(el, event){ if(startpoint && endpoint && swipedirection(startpoint.x, startpoint.y, endpoint.x, endpoint.y) === swipe){ callback.call(el, event); return true; } } el.addeventlistener('touchstart', function(event){ var self = this, touchpoint = event.touches[0]; if(isstoppropagation){ event.stoppropagation(); } if(ispreventdefault){ event.preventdefault(); } startpoint = { x: math.floor(touchpoint.clientx), y: math.floor(touchpoint.clienty) }; timer = settimeout(function(){ //如果超时,清空本次touch数据 clearswipe(); }, touch.duration); }); el.addeventlistener('touchmove', function(event){ var self = this, touchpoint = event.touches[0]; if(isstoppropagation){ event.stoppropagation(); } if(ispreventdefault){ event.preventdefault(); } if(startpoint){ endpoint = { x: math.floor(touchpoint.clientx), y: math.floor(touchpoint.clienty) }; if(triggeronmove){ if(execswipe(self, event)){ clearswipe(); } } } }); el.addeventlistener('touchend', function(event){ if(isstoppropagation){ event.stoppropagation(); } if(ispreventdefault){ event.preventdefault(); } execswipe(self, event); clearswipe(); }); } touch.swipeleft = function(el, callback, options){ if(options){ bindswipe(el, 'swipeleft', callback, options.triggeronmove, options.isstoppropagation, options.ispreventdefault); }else{ bindswipe(el, 'swipeleft', callback); } }; touch.swiperight = function(el, callback, options){ if(options){ bindswipe(el, 'swiperight', callback, options.triggeronmove, options.isstoppropagation, options.ispreventdefault); }else{ bindswipe(el, 'swiperight', callback); } }; touch.swipeup = function(el, callback, options){ if(options){ bindswipe(el, 'swipeup', callback, options.triggeronmove, options.isstoppropagation, options.ispreventdefault); }else{ bindswipe(el, 'swipeup', callback); } }; touch.swipedown = function(el, callback, options){ if(options){ bindswipe(el, 'swipedown', callback, options.triggeronmove, options.isstoppropagation, options.ispreventdefault); }else{ bindswipe(el, 'swipedown', callback); } }; return touch; })(); // 注册jquery方法 if($ && $.fn){ $.fn.extend({ rhuiswipe: function(name, callback, opts){ var fnswipe = rhui.mobile[name]; if(this.length > 0 && fnswipe){ this.each(function(){ fnswipe(this, callback, opts); }); } return this; } }); } $('.clearfix').rhuiswipe('swipeleft', function(event){ if(start>top){ return; }else{ start=start+li_w; var a=-start; $(this).css({"margin-left":""+a+"px",'-webkit-transition':'500ms linear'} ); } }, { isstoppropagation: true, ispreventdefault: false, triggeronmove: true }); $('.clearfix').rhuiswipe('swiperight', function(event){ if(start==0){ return; }else{ start=start-li_w; var a=-start; $(this).css({"margin-left":""+a+"px",'-webkit-transition':'500ms linear'} ); } }, { isstoppropagation: true, ispreventdefault: false, triggeronmove: true }); } //判断是pc还是手机端打开页面 var ww=$(window).width(); if(ww>"768"){ navpc(); pcclearfix(); } else{ fenlei() andriodnav(); } });