小編給大家分享一下如何使用javascript實現圖片輪播,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創新互聯公司于2013年開始,先為新民等服務建站,新民等地企業,進行企業商務咨詢服務。為新民企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。
因為自己是新手自學不久,所以代碼有很多不規范的地方,請原諒。
html部分代碼:
<div id="head"> <button id="prev" onmousedown="p()" onmouseout="cal()"><</button> <img height="500px" width="500px" src="image/dell.jpg" alt="Dell"> <button id="next" onmousedown="n()" onmouseout="cal()">></button> </div>
CSS部分代碼:
<style type="text/css">
*
{
margin: 0;
padding: 0;
}
#head
{
width:800px;
height:500px;
border-radius: 5px;
border: 2px solid pink;
margin: 200px auto;
text-align: center;
}
#prev
{
width: 30px;
height: 30px;
border: 0px;
border-radius: 5px;
background-color:white;
color: black;
position: relative;
margin-top: 250px;
float: left;
}
#next
{
width: 30px;
height: 30px;
border: 0px;
border-radius: 5px;
background-color:white;
color: black;
position: relative;
margin-top: 250px;
float: right;
}
</style>javascript部分代碼:
<script>
var prev=document.getElementById("prev");
var next=document.getElementById("next");
var img=document.getElementsByTagName("img")[0];
var imgArr=["image/dell.jpg/dell.jpg","image/dell.jpg/sony.jpg","image/dell.jpg/費列羅.jpg","image/dell.jpg/Nike.jpg"];
var index=0;
//點擊左箭頭,切換上一張
function p(){
if(index==0)
{
index=imgArr.length;
}
index--;
img.src=imgArr[index];
}
//點擊右箭頭,切換下一張
function n(){
if(index==imgArr.length)
{
index=0;
}
img.src=imgArr[index];
index++;
}
//設置自動播放
time=setInterval("p()",2000);
//鼠標移入箭頭內,停止自動播放
function cal(){
clearInterval(time);
}
</script>以上是“如何使用javascript實現圖片輪播”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注創新互聯行業資訊頻道!
當前標題:如何使用javascript實現圖片輪播
標題來源:http://m.kartarina.com/article32/gciesc.html
成都網站建設公司_創新互聯,為您提供關鍵詞優化、商城網站、電子商務、網頁設計公司、網站導航、手機網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯