原生js點擊輪播圖效果

來源:互聯網
上載者:User

標籤:.class   order   head   png   img   utf-8   win   document   end   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
<title>原生js輪播效果</title>
</head>
<body>
<style>
#app{
width: 100%;
padding: 20px;
position: relative;
overflow: hidden;
}
ul{
display: inline-block;
}
#app1{
display: inline-block;
overflow: hidden;
position: relative;
}
li{
float: left;
padding: 0 10px;
box-sizing: border-box;
border: 1px solid red;
display: none;
}
img{
width: 140px;
height: 140px;
}
#app2{
position: absolute;
bottom:10px;
width: 100%;
}
#app2 div{
display: inline-block;
width: 25%;
text-align: center;
}
#app2 div span{
display: inherit;
border-radius: 10px;
padding: 3px;
background: black;
color: #fff;
}
#app2 div .active{
background: red;
}
</style>

<div id="app">
<div id="app1">
<ul>
<li style="display: block">
<img src="img/1.png">
</li>
<li>
<img src="img/2.png">
</li>
<li>
<img src="img/3.png">
</li>
<li>
<img src="img/4.png">
</li>
</ul>
<div id="app2">
</div>

</div>
<div id="abc">

</div>
</div>

<script>
window.onload=function () {
var arrlist=null;
var timers=null;
function lunbo() {
var app1=document.getElementById(‘app1‘);
var li=app1.getElementsByTagName(‘li‘);
var app2=document.getElementById(‘app2‘);
var text=document.getElementById(‘text‘);
var appabc=document.getElementById(‘abc‘);
arrlist=[‘第一張‘,‘第二張‘,‘第三張‘,‘第四張‘];
for(var i=0;i<li.length;i++){
//建立標記
var span=document.createElement(‘div‘);
span1=document.createElement(‘span‘);
span1.innerHTML=i;
span.appendChild(span1);
app2.appendChild(span);
}
var spanactive=document.getElementsByTagName(‘span‘);
//點擊操作
for(var i=0;i<spanactive.length;i++){
if(i==0){
spanactive[i].className=‘active‘
}
spanactive[i].index=i;
spanactive[i].onclick=function () {
for(var j=0;j<spanactive.length;j++){
spanactive[j].className=‘‘;
li[j].style.display=‘none‘;
}
this.className=‘active‘;
li[this.index].style.display=‘block‘;
appabc.innerHTML=arrlist[this.index]
}
appabc.innerHTML=arrlist[0]
}
}

lunbo()
}
</script>
</body>
</html>

原生js點擊輪播圖效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.