輪播源碼是高仿個人XX同窗的,最終實現了旋轉木馬的輪播效果。javascript
圖是截取的我我的網站,內容尚未作更改和優化,整體效果以下:css
輪播效果:自動輪播,鼠標懸停會有左、右箭頭,可進行手動輪播前端
輪播部分頁面代碼以下:java
<div id="myself" class="me">
<div id="aboutme">
<img src="img/aboutme.png">
</div>
<p>我是一個善於接收新知識的人,並時刻保持對前端最新技術的高度敏感</p>
<p>具有做爲開發人員的基本要求:作事踏實認真、責任心強、團隊協做能力。
對領導佈置的任務始終追尋着高效、高質解決方案
</p>
<div class="wrap">
<div class="slidepic" id="slidepic">
<ul>
<li style="z-index: 2; width: 450px; height: 253px; left: -166px; top: 0px; opacity: 0;" ><img src="../img/lb1.jpg" style="width: 100%; height: 100%;" ></li>
<li style="z-index: 3; width: 450px; height: 253px; left: -166px; top: 79px; opacity: 0.8;" ><img src="../img/lb2.jpg" style="width: 100%; height: 100%;" ></li>
<li style="z-index: 4; width: 650px; height: 365px; left: 0px; top: 20px; opacity: 1;" ><img src="../img/lb3.jpg" style="width: 100%; height: 100%;" ></li>
<li style="z-index: 3; width: 450px; height: 253px; left: 390px; top: 79px; opacity: 0.8;" ><img src="../img/lb4.jpg" style="width: 100%; height: 100%;" ></li>
<li style="z-index: 2; width: 450px; height: 253px; left: 390px; top: 0px; opacity: 0;" ><img src="../img/lb5.jpg" style="width: 100%; height: 100%;" ></li>
</ul>
<div class="toggle" style="display: none;">
<a href="javascript:;" class="prev"></a>
<a href="javascript:;" class="next"></a>
</div>
</div>
</div>
</div>
c
樣式以下(引入bootstrap,代碼未優化,請自行整理):
.wrap {
width: 650px;
height: 365px;
margin-top: 10px;
margin-left: auto;
margin-right: auto;
}
.slidepic {
position: relative;
height: 365px;
}
.toggle {
position: absolute;
z-index: 10;
width: 100%;
height: 100%;
display: none;
}
.toggle a {
position: absolute;
left: -100px;
top: 40%;
width: 76px;
height: 112px;
background: url(/img/prev.png) 0 0 no-repeat;
}
.me{
margin: 0;
padding: 0;
font-size: 12px;
color: #666;
text-align:center;
padding-top:15px;
}
.slidepic>ul>li{
display: list-item;
text-align: -webkit-match-parent;
}
#myself {
position: relative;
width: 100%;
height: 700px;
overflow: hidden;
background-color: #DEDEDE;
}
.slidepic ul {
position: absolute;
left: 0;
top:0px;
z-index: 1;
list-style-type: none;
}
ul,menu,dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;
}
.toggle .next{
right:0px;
left:670px;
background-image: url(/img/next.png);
}
div {
display: block;
}
body {
overflow-x: hidden;
}
div#aboutme, div#case1 {
width: 292px;
height: 127px;
margin: 20px auto;
margin-bottom: 20px;
}
#myself p, #case p {
width: 800px;
margin: 0px auto;
text-align: center;
margin-top: 10px;
color: #8C8C8C;
}
.slidepic li {
position: absolute;
width: 450px;
height: 253px;
left: 0px;
top: 0;
background-color: #6475ae;
list-style-type: none;
}
代碼段以下(引入jquery):
$(function(){ var $slidepic = $('#slidepic'); var aLi = $slidepic.find('li'); var timer = null; var off = true; //定義li定位數據 var pos = [ { width:450, height:253, left:-166, top:0, opacity:0, z:2 }, { width:450, height:253, left:-166, top:79, opacity:0.8, z:3 }, { width:650, height:365, left:0, top:20, opacity:1, z:4 }, { width:450, height:253, left:390, top:79, opacity:0.8, z:3 }, { width:450, height:253, left:390, top:0, opacity:0, z:2 } ] //設置li定位 fnMove() //上一個按鈕 $slidepic.find('.prev').on('click',function(){ if(off){ off = false; fnMove(true) } }) //下一個按鈕 $slidepic.find('.next').on('click',function(){ if(off){ off = false; fnMove(false) } }) //li運動函數 function fnMove(b){ if(typeof(b) != 'undefined'){ //判斷參數有沒有傳,沒有就設置li位置,傳了就是按鈕點擊 if(b){ pos.push(pos.shift()) }else{ pos.unshift(pos.pop()) } } $.each(pos, function(i, val) { aLi.eq(i).css('zIndex',pos[i].z).stop().animate(pos[i],500,function(){ off = true; }); }); } //開啓定時器自動播放 timer = setInterval(function(){ fnMove(true) },3000) //暫停繼續播放,顯示隱藏左右切換按鈕 $slidepic.hover(function(){ clearInterval(timer) $(this).find('.toggle').fadeIn(); },function(){ clearInterval(timer) timer = setInterval(function(){ fnMove(true) },5000) $(this).find('.toggle').fadeOut(); })}) 大氣美觀的輪播圖~