本文實(shí)例為大家分享了myFocus輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
完整文件及代碼: https://github.com/erdouzhang/slider-myFocus
step1.頁面引入相關(guān)文件

<link rel="stylesheet" href="lib/mf-pattern/mF_slide3D.css" rel="external nofollow" ><script src="lib/myfocus-2.0.4.min.js"></script><script src="lib/mf-pattern/mF_slide3D.js"></script>
step2.寫html結(jié)構(gòu)、js
css樣式如下:
<style type="text/css"> #boxID { width: 560px; height: 300px; margin: 0 auto; padding-top: 100px; } </style>html結(jié)構(gòu)、簡單js 如下:
<body> <div id="boxID"> <!--焦點(diǎn)圖盒子--> <div class="loading"><img src="img/1m.jpg" height="300" width="560" alt="請(qǐng)稍候..." /></div> <!--載入畫面(可刪除)--> <div class="pic"> <!--內(nèi)容列表(li數(shù)目可隨意增減)--> <ul> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="img/1m.jpg" height="300" width="560" thumb="" alt="標(biāo)題1" text="詳細(xì)描述1" /></a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="img/2m.jpg" height="300" width="560" thumb="" alt="標(biāo)題2" text="詳細(xì)描述2" /></a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="img/3m.jpg" height="300" width="560" thumb="" alt="標(biāo)題3" text="詳細(xì)描述3" /></a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="img/4m.jpg" height="300" width="560" thumb="" alt="標(biāo)題4" text="詳細(xì)描述4" /></a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><img src="img/5m.jpg" height="300" width="560" thumb="" alt="標(biāo)題5" text="詳細(xì)描述5" /></a> </li> </ul> </div> </div> <script src="lib/myfocus-2.0.4.min.js"></script> <script src="lib/mf-pattern/mF_slide3D.js"></script> <!-- 你可以簡單的調(diào)用-只設(shè)置它的盒子id,其它參數(shù)全部默認(rèn)設(shè)置: --> <script type="text/javascript"> myFocus.set({ id: 'boxID', pattern: 'mF_fancy' }); </script></body>js代碼還可以更詳細(xì)點(diǎn)如下:
<script type="text/javascript">myFocus.set({ id:'boxID',//焦點(diǎn)圖盒子ID pattern:'mF_fancy',//風(fēng)格應(yīng)用的名稱 time:3,//切換時(shí)間間隔(秒) trigger:'click',//觸發(fā)切換模式:'click'(點(diǎn)擊)/'mouseover'(懸停) width:450,//設(shè)置圖片區(qū)域?qū)挾?像素) height:296,//設(shè)置圖片區(qū)域高度(像素) txtHeight:'default'//文字層高度設(shè)置(像素),'default'為默認(rèn)高度,0為隱藏});</script>效果圖:

風(fēng)格文件是不需要在使用時(shí)手動(dòng)引入,myFocus會(huì)根據(jù)你的pattern設(shè)置,尋找myFocus庫文件目錄下的mf-pattern目錄,當(dāng)找到相應(yīng)的風(fēng)格文件后,自動(dòng)引入。
這樣,你只需要把你的風(fēng)格文件放在myFocus庫文件目錄下的mf-pattern目錄內(nèi),即可實(shí)現(xiàn)自動(dòng)引入機(jī)制。
例如,你的myFocus-2.0.0.min.js文件放在js目錄,那么,只需在js目錄內(nèi)建立一個(gè)mf-pattern的子目錄,這個(gè)子目錄便是myFocus程序可以識(shí)別的存放風(fēng)格文件的目錄。
在mf-pattern目錄中,也存在一個(gè)img的子目錄,它是存放某些風(fēng)格的圖片文件,雖然并不是每款風(fēng)格都會(huì)有圖片文件。
建議把所有的風(fēng)格文件都存放在這個(gè)mf-pattern目錄,這樣你就可以隨意切換你的風(fēng)格了,而且它是按需加載,并不會(huì)引入其它多余的文件。myFocus的整個(gè)加載量(主庫+風(fēng)格)平均只有12KB左右。
另外需要說明的是,這個(gè)自動(dòng)引入機(jī)制已經(jīng)做的足夠智能,它并不會(huì)重復(fù)引入風(fēng)格文件,例如當(dāng)你已經(jīng)手動(dòng)引入風(fēng)格文件,又或者干脆把某風(fēng)格的js代碼寫在頁面上,這時(shí)myFocus并不會(huì)再次尋找引入風(fēng)格文件,而是直接讀取頁面上的。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注