js中開關(guān)變量使用實(shí)例
更新時(shí)間:2017年02月24日 14:31:07 作者:marie0119
本文主要分享了js中開關(guān)變量使用實(shí)例的代碼,具有很好的參考價(jià)值,下面跟著小編一起來看下吧
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; font-family: "微軟雅黑"; } #wrap{ width: 400px; height: 500px; border: 1px solid #ccc; margin: 20px auto; position: relative; overflow: hidden; background: #f1f1f1; } #wrap a{ width: 40px; height: 50px; background:rgba(0,0,0,.4); /*border: 1px solid #fff;*/ position: absolute; top: 50%; margin-top: -25px; text-align: center; text-decoration: none; line-height: 50px; color: white; font-size: 30px; } #wrap a:hover{ background:rgba(0,0,0,.9); } #prev{ left: 10px; } #next{ right: 10px; } #note,#span1{ position: absolute; left: 0; width: 400px; height: 30px; line-height: 30px; text-align: center; color: white; background: rgba(0,0,0,.6); } #note{ bottom: 0; } #span1{ top: 0; } #img1{ width: 400px; height: 500px; } section{ width: 400px; height: 50px; margin: 30px auto 0; line-height: 50px; text-align: center; } section input{ padding: 5px 15px; margin-right: 10px; } .pink{ background: pink; color: white; } </style> </head> <script> window.onload=function(){ var oPrev=document.getElementById('prev'); var oNext=document.getElementById('next'); var oNote=document.getElementById('note'); var oSpan=document.getElementById('span1'); var oImg=document.getElementById('img1'); var arrURL=['https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488463139&di=af377bee44237b092b20f1f7c86f2eb6&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.wed114.cn%2Fjiehun%2Fuploads%2Fallimg%2F160304%2F52_160304170213_3.jpg','https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488463080&di=a0ba47cd212e8f5755a2f42738511a2e&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.6a8a.com%2Fuploadfile%2F2017%2F0809%2F2016071617592321137.jpg','https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488463040&di=f9290db609a0994bdbd7221e644904ba&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.wed114.cn%2Fjiehun%2Fuploads%2Fallimg%2F160405%2F52_160405165047_3.jpg','https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488462814&di=e1dacd05467c01a13d9eb4d800853f20&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.wed114.cn%2Fjiehun%2Fuploads%2Fallimg%2F160304%2F52_160304160734_5.jpg','https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1487868087852&di=3011f4a2b23b63559c32f8f154ad0a3a&imgtype=0&src=http%3A%2F%2Fwww.wed114.cn%2Fjiehun%2Fuploads%2Fallimg%2F160411%2F52_160411172520_1.jpg']; var arrNote=['多肉植物佛珠怎么養(yǎng) 翡翠珠的養(yǎng)殖方法','多肉植物紫弦月的養(yǎng)殖方法','多肉植物球松怎么養(yǎng) 球松的養(yǎng)殖方法','是一種小巧又可愛的 多肉植物','多肉植物藍(lán)松怎么繁殖']; var num=0; var oBtn=document.getElementsByTagName('input'); var onOff=true; oBtn[0].onclick=function(){ onOff=true; this.className='pink'; this.nextSibling.className=''; } oBtn[1].onclick=function(){ onOff=false; this.className='pink'; this.previousSibling.className=''; } function fnTab(){ oSpan.innerHTML=num+1+'/'+arrURL.length; oImg.src=arrURL[num]; oNote.innerHTML=arrNote[num]; } fnTab(); oPrev.onclick=function(){ num--; if(num==-1){ if(onOff){ num=arrNote.length-1; }else{ alert('已經(jīng)是第一張圖片了,親!'); num=0; } } fnTab(); } oNext.onclick=function(){ num++; if(num==arrNote.length){ if(onOff) { num=0; }else{ alert('已經(jīng)是第一張圖片了,親!'); num=arrNote.length-1; } } fnTab(); } } </script> <body> <section> <input type="button" value="循環(huán)播放" class="pink"/><input type="button" value="順序播放" /> </section> <div id="wrap"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="prev"><</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" id="next">></a> <p id="note">圖片文字加載中......</p> <span id="span1">數(shù)量正在計(jì)算中......</span> <img id="img1" /> </div> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
- JS基于開關(guān)思想實(shí)現(xiàn)的數(shù)組去重功能【案例】
- js實(shí)現(xiàn)按鈕開關(guān)單機(jī)下拉菜單效果
- JavaScript實(shí)現(xiàn)開關(guān)等效果
- js操作css屬性實(shí)現(xiàn)div層展開關(guān)閉效果的方法
- javascript結(jié)合CSS實(shí)現(xiàn)蘋果開關(guān)按鈕特效
- JS 簡單展開關(guān)閉切換代碼
- jQuery 如何實(shí)現(xiàn)一個(gè)滑動(dòng)按鈕開關(guān)
- jQuery+PHP打造滑動(dòng)開關(guān)效果
- 使用jQuery和PHP實(shí)現(xiàn)類似360功能開關(guān)效果
- JQuery對(duì)class屬性的操作實(shí)現(xiàn)按鈕開關(guān)效果
- JS/jQuery實(shí)現(xiàn)簡單的開關(guān)燈效果【案例】
相關(guān)文章
微信小程序?qū)崿F(xiàn)幸運(yùn)大轉(zhuǎn)盤功能的示例代碼
這篇文章主要介紹了如何在微信小程序中實(shí)現(xiàn)幸運(yùn)大轉(zhuǎn)盤功能,參與用戶點(diǎn)擊抽獎(jiǎng)便可抽取輪盤的獎(jiǎng)品,感興趣的小伙伴可以跟隨小編一起動(dòng)手試一試2022-03-03利用JS實(shí)現(xiàn)AI自動(dòng)玩貪吃蛇
這篇文章主要為大家詳細(xì)介紹了如何利用JS實(shí)現(xiàn)AI版自動(dòng)玩貪吃蛇小游戲,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)JS游戲開發(fā)有一定幫助,需要的可以參考一下2022-06-06詳解webpack-dev-server使用http-proxy解決跨域問題
這篇文章主要介紹了詳解webpack-dev-server使用http-proxy解決跨域問題,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01基于構(gòu)造函數(shù)的五種繼承方法小結(jié)
下面小編就為大家?guī)硪黄跇?gòu)造函數(shù)的五種繼承方法小結(jié)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07一個(gè)多瀏覽器支持的背景變暗的div并可拖動(dòng)提示窗口功能的代碼
兼容IE、Firefox、Opera前幾天在網(wǎng)上找了許多資料,看了不少兄弟的源碼,一直找不到合適的,要不就是拖動(dòng)有問題,要不就是不兼容Firefox,所以自已寫了一個(gè),下面是代碼:2008-04-04gulp-htmlmin壓縮html的gulp插件實(shí)例代碼
這篇文章主要介紹了gulp-htmlmin壓縮html的gulp插件實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-06-06