jQuery圖片輪播

來源:互聯網
上載者:User

標籤:ack   document   alt   .com   html   :hover   var   image   code   

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>圖片輪播</title>
<style>
*{margin:0px;padding:0px;}
.one{
float:left;
position:relative;
left:0px;
top:0px;
margin-left:10px;
width:790px;
height:340px;
overflow:hidden;
}
.one ul li{
list-style:none;
}
.photo ul{
float:left;
position:absolute;
height:490px;
left:0px;
top:0px;
}
.photo ul li{
float:left;
padding:0px;
margin:0px;
}

.arrow span{
display:block;
position:absolute;
width:30px;
height:60px;
line-height:60px;
text-align:center;
background:rgba(0,0,0,0.2);
z-index:1;
font-size:20px;
color:#fff;
top:40%;
cursor:pointer;
display:none;

}
.arrow span:hover{
background:rgba(0,0,0,0.7);
}
.arrow .right{
right:0px;
}
.dot{
position:absolute;
z-index:!;
background:rgba(255,255,255,0.2);
font-size:26px;
bottom:15px;
left:300px;
border-radius:22px;
}
.dot ul{
margin:0px;
padding:0px;
}
.dot ul li{
float:left;
padding:0px;
margin:0px;
margin:0 5px;
cursor:pointer;
}
</style>
</head>

<body>
<div class="one">
<div>
<div class="photo">
<ul>
<li><img src="image/1.png" alt="1" /></li>
<li><img src="image/2.png" alt="2" /></li>
<li><img src="image/3.png" alt="3" /></li>
<li><img src="image/4.png" alt="4" /></li>
<li><img src="image/5.png" alt="5" /></li>
<li><img src="image/6.png" alt="6" /></li>
</ul>
</div>
<div class="arrow"><span class="iconfont left"></span> <span class="iconfont right"></span></div>
<div class="dot">
<ul>
<li>●</li>
<li>●</li>
<li>●</li>
<li>●</li>
<li>●</li>
<li>●</li>
</ul>
</div>
</div>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js" ></script>
<script>
$(document).ready(function(){
var ulWidth=$(‘.photo ul li‘).length*$(‘.photo ul li‘).eq(1).width();
$(‘.dot ul li‘).first().css(‘color‘,‘#db192a‘);
$(‘.photo ul‘).width(ulWidth);
$(‘.photo,.arrow span‘).hover(function(){$(‘.arrow span‘).toggle()})
function jdshow(){
var index=-$(‘.photo ul‘).position().left/$(‘.photo ul li‘).eq(1).width();
$(‘.dot ul li‘).css(‘color‘,‘#fff‘);
if(index==$(‘.photo ul li‘).length-1){index=-1}
$(‘.dot ul li‘).eq(index+1).css(‘color‘,‘#db192a‘);

if($(‘.photo ul‘).position().left==-(ulWidth-790)){
$(‘.photo ul‘).css(‘left‘,‘790px‘);//圖片寬度
$(‘.photo ul‘).clone().appendTo(‘.photo‘);
$(‘.photo ul:first‘).remove();
}
$(‘.photo ul‘).animate({
left:‘-=790px‘,
},10);

}
setInterval(jdshow,2000);

$(‘.arrow .right‘).click(function(){
jdshow();
});
$(‘.arrow .left‘).click(function(){
/*alert($(‘.jd-photo ul‘).position().left);*/
var index=-$(‘.photo ul‘).position().left/$(‘.photo ul li‘).eq(1).width();
$(‘.dot ul li‘).css(‘color‘,‘#fff‘);
$(‘.dot ul li‘).eq(index-1).css(‘color‘,‘#db192a‘);
if($(‘.photo ul‘).position().left==0){
$(‘.photo ul‘).css(‘left‘,-ulWidth);
$(‘.photo ul‘).clone().appendTo(‘.photo‘);
$(‘.photo ul:first‘).remove();
}
$(‘.photo ul‘).animate({
left:‘+=790px‘,
},10);
});
$(‘.dot ul li‘).click(function(){
var index=$(‘.dot ul li‘).index(this);
$(‘.photo ul‘).animate({
left:-index*790,
},10);
$(‘.dot ul li‘).css(‘color‘,‘#fff‘);
$(this).css(‘color‘,‘#db192a‘);
});
})
</script>
</body>
</html>

jQuery圖片輪播

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.