JS實(shí)現(xiàn)圖片切換特效
本文實(shí)例為大家分享了JS實(shí)現(xiàn)圖片切換的具體代碼,供大家參考,具體內(nèi)容如下
知識(shí)點(diǎn):
1.window.onload網(wǎng)頁(yè)全部加載完后再執(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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- HTML+JS實(shí)現(xiàn)“代碼雨”效果源碼(黑客帝國(guó)文字下落效果)
- JS實(shí)現(xiàn)黑客帝國(guó)文字下落效果
- js仿黑客帝國(guó)字母掉落效果代碼分享
- js模擬實(shí)現(xiàn)煙花特效
- js實(shí)現(xiàn)煙花特效
- JS實(shí)現(xiàn)商品櫥窗特效
- JS實(shí)現(xiàn)吸頂特效
- JavaScript實(shí)現(xiàn)聯(lián)動(dòng)菜單特效
- JS實(shí)現(xiàn)電商商品展示放大鏡特效
- JS實(shí)現(xiàn)音樂(lè)鋼琴特效
- JS實(shí)現(xiàn)音樂(lè)導(dǎo)航特效
- JS實(shí)現(xiàn)簡(jiǎn)單日歷特效
- JS實(shí)現(xiàn)秒殺倒計(jì)時(shí)特效
- JS實(shí)現(xiàn)導(dǎo)航欄樓層特效
- JS實(shí)現(xiàn)普通輪播圖特效
- javascript實(shí)現(xiàn)超好看的3D煙花特效
- javascript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊生成文字特效
- Javascript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊冒泡特效
- JS實(shí)現(xiàn)小星星特效
- JS實(shí)現(xiàn)星星海特效
- JS+CSS+HTML實(shí)現(xiàn)“代碼雨”類(lèi)似黑客帝國(guó)文字下落效果
相關(guān)文章
用js實(shí)現(xiàn)手把手教你月入萬(wàn)刀(轉(zhuǎn)貼)
用js實(shí)現(xiàn)手把手教你月入萬(wàn)刀(轉(zhuǎn)貼)...2007-11-11Bootstrap警告(Alerts)的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Bootstrap警告(Alerts)的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03給html超鏈接設(shè)置事件不使用href來(lái)完成跳
有時(shí)候我們需要使用a這個(gè)超級(jí)鏈接,而又不使用href來(lái)完成跳轉(zhuǎn),針對(duì)這個(gè)問(wèn)題,可以采用下面的解決方案2014-04-04Three光源Target位置改變光照方向不變的問(wèn)題解決方法
這篇文章主要為大家介紹了Three光源Target位置改變光照方向不變的問(wèn)題及解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12