js運動應用實例解析
更新時間:2015年12月28日 09:49:50 投稿:lijiao
這篇文章主要針對js運動應用進行實例解析
本文為大家提供了兩個js運動應用實例,分享給大家,具體實現(xiàn)內(nèi)容如下
應用1,完成如下效果:
js代碼如下:
<script src="move.js"></script> <script> window.onload=function () { var oDiv=document.getElementById('play'); var aBtn=oDiv.getElementsByTagName('ol')[0].getElementsByTagName('li'); var oUl=oDiv.getElementsByTagName('ul')[0]; var now=0; for(var i=0;i<aBtn.length;i++) { aBtn[i].index=i; aBtn[i].onclick=function () { now=this.index; tab(); }; } function tab() { for(var i=0;i<aBtn.length;i++) { aBtn[i].className=''; } aBtn[now].className='active'; startMove(oUl, {top: -150*now}); } function next() { now++; if(now==aBtn.length){now=0;} tab(); } var timer=setInterval(next, 2000); oDiv.onmouseover=function (){clearInterval(timer);}; oDiv.onmouseout=function (){timer=setInterval(next, 2000);}; }; </script>
應用2,完成如下效果:
代碼如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style type="text/css"> ..... </style> <script type="text/javascript" src="move.js"></script> <script type="text/javascript"> window.onload=function () { var oBtn=document.getElementById('but'); var oBottom=document.getElementById('zns_bottom'); var oBox=document.getElementById('zns_box'); var oBtnClose=document.getElementById('btn_close'); oBox.style.display='block'; var initBottomRight=parseInt(getStyle(oBottom, 'right')); var initBoxBottom=parseInt(getStyle(oBox, 'bottom')); oBox.style.display='none'; oBtn.onclick=openHandler; oBtnClose.onclick=closeHandler; function openHandler() { startMove(oBottom, {right: 0}, function (){ oBox.style.display='block'; startMove(oBox, {bottom: 0}); }); oBtn.className='but_hide'; oBtn.onclick=closeHandler; } function closeHandler() { startMove(oBox, {bottom: initBoxBottom}, function (){ oBox.style.display='none'; startMove(oBottom, {right: initBottomRight}, function (){ oBtn.className='but_show'; }); }); oBtn.onclick=openHandler; } }; </script> </head> <body> ...... </body> </html>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。
相關文章
JavaScript函數(shù)節(jié)流和函數(shù)防抖之間的區(qū)別
本文主要介紹了JavaScript函數(shù)節(jié)流和函數(shù)防抖之間的區(qū)別。具有很好的參考價值,下面跟著小編一起來看下吧2017-02-02javascript實現(xiàn)div浮動在網(wǎng)頁最頂上并帶關閉按鈕效果實例
我們有時會看到有些網(wǎng)站最頂部一直會跟著我們滾動而滾動了,這種方法其實很簡單,下面我來給大推薦一個javascript實現(xiàn)div浮動在網(wǎng)頁最頂上并帶關閉按鈕效果2013-08-08JS構造函數(shù)與原型prototype的區(qū)別介紹
下面小編就為大家?guī)硪黄狫S構造函數(shù)與原型prototype的區(qū)別介紹。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07JS獲取URL中參數(shù)值(QueryString)的4種方法分享
今天碰到要在一個頁面獲取另外一個頁面url傳過來的參數(shù),一開始很本能的想到了用 split("?")這樣一步步的分解出需要的參數(shù)。后來想了一下,肯定會有更加簡單的方法的!所以在網(wǎng)上找到了幾個很又簡單實用的方法,mark下。2014-04-04