最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript實現(xiàn)圖片輪播代碼

 更新時間:2019年07月09日 15:41:16   作者:Timorls  
這篇文章主要為大家詳細介紹了javascript實現(xiàn)圖片輪播代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

javascript圖片輪播代碼,供大家參考,具體內(nèi)容如下

因為自己是新手自學不久,所以代碼有很多不規(guī)范的地方,請原諒。

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);
 
 //鼠標移入箭頭內(nèi),停止自動播放
 function cal(){
 clearInterval(time);
 }

</script>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

古交市| 上蔡县| 金坛市| 浦东新区| 杭锦后旗| 黄骅市| 蕉岭县| 芜湖县| 云浮市| 临漳县| 凤城市| 右玉县| 周宁县| 永康市| 沾益县| 耒阳市| 左贡县| 井研县| 莫力| 栖霞市| 繁昌县| 洞头县| 闸北区| 泽州县| 清苑县| 罗城| 宣汉县| 云霄县| 德钦县| 郓城县| 海城市| 温宿县| 紫金县| 房山区| 贡嘎县| 宜昌市| 河北区| 临高县| 本溪市| 大余县| 大理市|