JS實(shí)現(xiàn)圖片切換特效
本文實(shí)例為大家分享了JS實(shí)現(xiàn)圖片切換的具體代碼,供大家參考,具體內(nèi)容如下
知識(shí)點(diǎn):
1.window.onload網(wǎng)頁全部加載完后再執(zhí)行
2.獲取元素 設(shè)置屬性
3.臨界情況判斷
運(yùn)行效果:
點(diǎn)擊上一張下一章切換圖片
代碼:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <style> #box{ width: 1200px; margin: 0 auto; } </style> <body> <div id="box"> <img id="icon" src="images/阿魯1.gif" alt=""> <p></p> <button id="prep">上一張</button> <button id="next">下一張</button> </div> <script> window.onload = function (ev) { // 1. 獲取標(biāo)簽 var prep = document.getElementById('prep'); var next = document.getElementById('next'); var icon = document.getElementById('icon'); // 2. 點(diǎn)擊 var currentIndex = 1, minIndex=1, maxIndex=10; prep.onclick = function (ev1) { if (currentIndex === minIndex){ currentIndex = maxIndex; }else{ currentIndex--; } icon.setAttribute('src','images/阿魯'+ currentIndex +'.gif'); }; next.onclick = function (ev1) { if (currentIndex === maxIndex){ currentIndex = minIndex; }else { currentIndex++; } icon.setAttribute('src','images/阿魯'+ currentIndex +'.gif'); } } </script> </body> </html>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:Javascript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊冒泡特效
欄 目:JavaScript
下一篇:Vue移動(dòng)端實(shí)現(xiàn)圖片上傳及超過1M壓縮上傳
本文標(biāo)題:JS實(shí)現(xiàn)圖片切換特效
本文地址:http://mengdiqiu.com.cn/a1/JavaScript/9410.html
您可能感興趣的文章
- 04-02java后端代碼分頁 java后端實(shí)現(xiàn)分頁page
- 01-10Echarts實(shí)現(xiàn)單條折線可拖拽效果
- 01-10在Vue項(xiàng)目中使用Typescript的實(shí)現(xiàn)
- 01-10js實(shí)現(xiàn)上傳圖片并顯示圖片名稱
- 01-10Vue中使用Lodop插件實(shí)現(xiàn)打印功能的簡單方法
- 01-10echarts實(shí)現(xiàn)折線圖的拖拽效果
- 01-10d3.js實(shí)現(xiàn)圖形縮放平移
- 01-10小程序簡單兩欄瀑布流效果的實(shí)現(xiàn)
- 01-10微信小程序批量上傳圖片到七牛(推薦)
- 01-10H5實(shí)現(xiàn)手機(jī)拍照和選擇上傳功能


閱讀排行
本欄相關(guān)
- 04-02javascript點(diǎn)線,點(diǎn)線的代碼
- 04-02javascript潛力,javascript強(qiáng)大嗎
- 04-02javascript替換字符串,js字符串的替換
- 04-02javascript移出,js 移入移出
- 04-02包含javascript舍的詞條
- 04-02javascript并行,深入理解并行編程 豆瓣
- 04-02javascript匿名,js匿名方法
- 04-02javascript警報(bào),JavaScript警告
- 04-02javascript遮蓋,JavaScript遮蓋PC端頁面
- 04-02javascript前身,javascript的前身
隨機(jī)閱讀
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10C#中split用法實(shí)例總結(jié)
- 01-11ajax實(shí)現(xiàn)頁面的局部加載
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05織夢dedecms什么時(shí)候用欄目交叉功能?
- 01-10使用C語言求解撲克牌的順子及n個(gè)骰子
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文