JS實(shí)現(xiàn)圖片切換特效
更新時間:2019年12月23日 17:11:52 作者:KaiSarH
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)圖片切換特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了JS實(shí)現(xiàn)圖片切換的具體代碼,供大家參考,具體內(nèi)容如下
知識點(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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- HTML+JS實(shí)現(xiàn)“代碼雨”效果源碼(黑客帝國文字下落效果)
- JS實(shí)現(xiàn)黑客帝國文字下落效果
- js仿黑客帝國字母掉落效果代碼分享
- js模擬實(shí)現(xiàn)煙花特效
- js實(shí)現(xiàn)煙花特效
- JS實(shí)現(xiàn)商品櫥窗特效
- JS實(shí)現(xiàn)吸頂特效
- JavaScript實(shí)現(xiàn)聯(lián)動菜單特效
- JS實(shí)現(xiàn)電商商品展示放大鏡特效
- JS實(shí)現(xiàn)音樂鋼琴特效
- JS實(shí)現(xiàn)音樂導(dǎo)航特效
- JS實(shí)現(xiàn)簡單日歷特效
- JS實(shí)現(xiàn)秒殺倒計(jì)時特效
- 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)“代碼雨”類似黑客帝國文字下落效果
相關(guān)文章
用js實(shí)現(xiàn)手把手教你月入萬刀(轉(zhuǎn)貼)
用js實(shí)現(xiàn)手把手教你月入萬刀(轉(zhuǎn)貼)...2007-11-11Bootstrap警告(Alerts)的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了Bootstrap警告(Alerts)的實(shí)現(xiàn)方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03Three光源Target位置改變光照方向不變的問題解決方法
這篇文章主要為大家介紹了Three光源Target位置改變光照方向不變的問題及解決方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12