<元字元集=“UTF-8”><腳本類型=“text/javascript”>(function(){ setSize (); window.onresize = setSize; function setSize(){ var html = document.documentElement; var htmlW = html.clientWidth; html.style.fontSize = htmlW / 16 + " px"; }})(); <標題>文檔<br>body {<br> margin: 0;<br>背景:#ccc;<br>} <br>ul {<br> 邊距:0;<br> 填滿:0;<br> 清單樣式:無;<br>}<br>.navWrap {<br>位置:相對;<br> 邊框底部:1px 實心#000;<br> 背景:#f1f1f1;<br> 高度:2.4rem;<br> 溢出:隱藏;<br>}<br>#navs { <br> 位置:絕對;<br> 左:0;<br> 頂部:0;<br> 空白:nowrap;<br>}<br>#navs li {<br> 顯示:內聯區塊;<br> 字型: .8rem/2.4rem "宋體";<br># 內邊距: 0 1rem;<br>#}<br>#navs li:nth-of-type(1) {<br> 背景: # fff;<br>}<br>#navs li:nth-last-of-type(1) {<br> 背景: #fff;<br>}<br>#navs a {<br> 文字裝飾: none ;<br> 顏色: #000;<br>}<br><br><script type="text/javascript" src="js/startmove.js?1.1.11"> script> <br/><br/><body><br/><nav class="navWrap"><br/> <ul id="navs"><br/> <li 類別="活動"><a href= "javascript:;" target="_blank">首頁</a></li><li><a href="javascript:;" target="_blank">MV</a></li><li><a href="javascript:;" target="_blank">悅單</a></li><li><a href="javascript:;" target="_blank">V榜</a></li><li><a href="javascript:;" target="_blank">音樂</a></li><li><a href="javascript:;" target="_blank">商城</a></li><li><a href="javascript:;" target="_blank">節目</a></li><li><a href="javascript:;" target="_blank">飯糰</a></li><li><a href="javascript:;" target="_blank">諮詢</a></li><li><a href="javascript:;" target="_blank">商城</a></li><li><a href="javascript:;" target="_blank">節目</a></li><li><a href="javascript:;" target="_blank">飯糰</a></li><li><a href="javascript:;" target="_blank">諮詢</a></li><li><a href="javascript:;" target="_blank">我的家</a></li><li><a href="javascript:;" target="_blank">APP下載</a></li><li><a href="javascript:;" target="_blank">熱門應用</a></li><br/> </ul><br/></nav><br/><腳本類型="text/javascript"> <br/>document.addEventListener('touchstart', function(e) {<br/> e.preventDefault();<br/>});<br/>(function(){<br/> var navWrap = document.querySelector(' . navWrap');<br/> var navs = document.querySelector('#navs');<br/> var start,startEl,lastTime,lastDis,lastSpeed;<br/> var min = 0;<br/> var max = 0 ; <br/> var TC = .25;//拉力係數<br/> /*<br/>lastTime 上一次時間<br/>lastDis 上一次位置<br/>lastSpeed 上一次速度<br/> */<br/> navWrap. addEventListener ('touchstart', function(e) {<br/> var touch = e.changedTouches[0];<br/> start = touch.pageX;<br/> startEl = css(navs,"left");<br/> lastTime = Date.now();<br/> lastDis = touch.pageX;<br/> min = navWrap.clientWidth - navs.offsetWidth;<br/> });<br/> navWrap.addEventListener('touchmove', function(e ) {<br/> var touch = e.changedTouches[0];<br/> var now = touch.pageX;<br/> var x = now - start + startEl;<br/> var nowTime = Date.now();<br/> 如果(x > 最大值){<br/>x *= TC;<br/> } else if(x < min) {<br/> // 為什麼位移的幅度沒有減少? <br/> x = (x - min)*TC + min;<br/> }<br/> css(navs,"left",x);<br/> lastSpeed = (touch.pageX - lastDis)/(nowTime - lastTime );<br/> //得到上一次和這次的滑動速度<br/> lastDis = touch.pageX;<br/> lastTime = nowTime;<br/> });<br/> navWrap.addEventListener('touchend', function (e) {<br/> //console.log(lastSpeed);//最後一次滑動的速度<br/> /* 速越快,緩衝的距離越大*/<br/> if(Date.now() - lastTime > 100){<br/> //如果最後一次的move時間和我抬起的時候,相差比較大,說明我在抬起之前,有一定時間沒有移動過,那鬆手之後,也應該保持不動<br/> lastSpeed = 0;<br/> }<br/> lastSpeed = Math.abs(lastSpeed) < .1?0:lastSpeed;<br/> var translate = lastSpeed * 200;//這是要緩衝出去距離<br/> translate = Math.abs(translate) > 1000?1000*(translate/Math.abs(translate)):translate;<br/> var target = translate + css(navs,"left");<br/># var type = "easeOutStrong";<br/> if(target > max){<br/> target = 0;<br/> type = "backOut";<br/> } else if(target < min){<br/> target = min;<br/> type = "backOut";<br/> }<br/> var time = Math.abs((target -css(navs,"left")) * 1.3);<br/> time = (time> ;0&&time<200)?200:time;<br/> console.log(time);<br/> startMove({<br/> el:navs,<br/> target: {<br/> left: target<br/> }, <br/> time: time,<br/> type: type<br/> });<br/> });<br/>})(); <br/></script><br/></body><br/></html></script></p> <p>//形式動畫公式<br>var Tween = {<br> 線性: function (t, b, c, d){<br> return c*t/d + b;<br> },<br> escapeIn: function(t, b, c, d){<br> return c*(t/=d)*t + b;<br> },<br> escapeOut: function(t, b, c, d ) ){<br> return -c *(t/=d)*(t-2) + b;<br> },<br> escapeBoth: function(t, b, c, d){<br> if ( (t/=d/2) 回傳 c/2*t*t + b;<br> }<br> 回傳 -c/2 * ((--t)*(t- 2) - 1) + b;<br> },<br> escapeInStrong: function(t, b, c, d){<br> return c*(t/=d)*t*t*t + b; <br> },<br> easyOutStrong: function(t, b, c, d){<br> return -c * ((t=t/d-1)*t*t*t - 1) + b; <br> },<br> easyBothStrong: function(t, b, c, d){<br> if ((t/=d/2) return c/2*t*t * t*t + b;<br> }<br> return -c/2 * ((t-=2)*t*t*t - 2) + b;<br> },<br> elasticIn: 函數( t, b, c, d, a, p){<br> if (t === 0) { <br> return b; <br> }<br> if ( (t /= d) == 1 ) {<br> return b+c; <br> }<br> if (!p) {<br> p=d*0.3; <br> }<br> if (!a || a a = c; <br> var s = p/4;<br> } else {<br> var s = p/(2*Math.PI) * Math.asin (c/a);<br> }<br> return - (a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;<br> },<br> elasticOut: function(t, b, c, d, a, p){<br> if (t === 0) {<br> return b;<br> }<br> if ( (t /= d ) == 1 ) {<br> return b+c;<br> }<br> if (!p) {<br> p=d*0.3;<br> }<br> if (!a || a <math.abs></math.abs> a = c;<br> var s = p / 4;<br> } else {<br> var s = p/(2*Math.PI) * Math . asin (c/a);<br> }<br> return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;<br> }, <br> elasticBoth: function(t, b, c, d, a, p){<br> if (t === 0) {<br> return b;<br> }<br> if ( (t /= d/2) == 2 ) {<br> return b+c;<br> }<br> if (!p) {<br> p = d*(0.3 * 1.5);<br> }<br> if ( !a || a a = c; <br> var s = p/4;<br> }<br> else {<br> var s = p/(2*Math.PI) * Math.asin (c/a);<br> }<br> if (t return - 0.5*(a*Math.pow(2,10*(t-=1)) * <br> Math.sin( (t*d-s)*(2 * Math.PI)/p )) + b;<br> }<br> return a*Math.pow(2,-10*(t-=1)) * <br> Math.sin( (t*d-s ) *(2*Math.PI)/p )*0.5 + c + b;<br> },<br> backIn: function(t, b, c, d, s){<br> if (typeof s = = '未定義') {<br> s = 1.70158;<br> }<br># return c*(t/=d)*t*((s+1)*t - s) + b;<br> } ,<br> backOut: function(t, b, c, d, s){<br> if (typeof s == 'undefined') {<br> s = 2.70158; //回縮的距離<br> }<br> return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;<br> } , <br> backBoth: function(t, b, c, d, s){<br> if (typeof s == 'undefined') {<br> s = 1.70158; <br> }<br> if ((t /= d/2 ) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;<br> }<br> 返回c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;<br> },<br>ounceIn: function(t, b, c, d){<br> return c - Tween['bounceOut'](d-t, 0, c, d) + b;<br> }, <br>ounceOut: function(t, b, c, d){<br> if ((t/=d) return c*(7.5625*t* t) + b;<br> } else if (t return c*(7.5625*(t-=(1.5/2.75))*t + 0.75) + b;<br> } else if (t return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;<br> }<br> return c*( 7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;<br> }, <br>ounceBoth: function(t, b, c, d){<br> if ( t 返回Tween['bounceIn'](t*2, 0, c, d) * 0.5 + b;<br> }<br> 返回Tween['bounceOut'](t *2-d, 0, c, d) * 0.5 + c*0.5 + b;<br> }<br>}<br>//取得或設定樣式<br>function css(el,attr,val){ <br> if( arguments.length == 2){<br> if(el.currentStyle){<br> val = el.currentStyle[attr];<br> } else {<br> val = getComputedStyle(el) [attr];<br> }<br> return parseFloat(val);<br> } else {<br> if(attr == "opacity"){<br> el.style.opacity = val;<br> el.style.filter = "alpha(opacity= "+val*100+")";<br> } else if(attr == "zIndex"){<br> el.style[attr] = Math.round( val);<br> }else {<br> el.style[attr] = val + "px";<br> }<br># }<br>}<br>//執行動畫<br>function startMove( init){<br>clearInterval(init.el.timer);<br>var t = 0; <br> var b = {};<br> var c = {};<br> var d = init.time/20;<br> for( var s in init.target){ <br> b[s] = css(init.el,s);<br> c[s] = init.target[s] - b[s];<br> } <br> init.el.timer = setInterval(function(){<br> t++;<br> if(t > d){<br> clearInterval(init.el.timer);<br> init.callBack&&init.callBack();<br> } else {<br> for(var init .target 中的s){<br> var val = Tween[init.type](t,b[s],c[s],d);<br> css(init.el,s,val);<br> }<br> }<br> },20);<br>}</p>#