jQ轮播图 jquery-1.8.3.js版
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
img{
width: 200px;
height: 150px;
}
.img{
width: 20001px;
position: absolute;
}
.img_item{
float: left;
}
#lun{
width: 200px;
height: 150px;
border: 1px solid saddlebrown;
overflow: hidden;
margin: 10px auto;
position: relative;
}
.btn{
position: absolute;
top: 75px;
}
.next{
right: 0;
}
.prev{
left: 0;
}
.nav{
position: absolute;
/*border: 1px solid turquoise;*/
left: 45px;
bottom: 10px;
}
.nav_item{
width: 20px;
height: 20px;
border-radius: 50%;
display: inline-block;
margin-left: 5px;
background: white;
text-align: center;
line-height: 20px;
}
.nav:first-child{
margin-left: 0;
}
.nav_item.active{
background: rosybrown;
} .nav_item{
cursor: pointer;
}
</style>
<script src="jquery-1.8.3.js"></script>
</head>
<body>
<div id="lun">
<!--图-->
<ul class="img">
<li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/2.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/3.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/4.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
</ul>
<!--下标-->
<ul class="nav">
<li class="nav_item active">1</li>
<li class="nav_item">2</li>
<li class="nav_item">3</li>
<li class="nav_item">4</li>
</ul>
<!--左右键-->
<button class="btn prev"><</button>
<button class="btn next">></button>
</div>
<script>
var n=0;
var size=$(".img_item").size();
/*右键函数*/
function ne(){
// alert(1)
n++;
// console.log(n);
dong();
diandian();
}
/*左键函数*/
function pr(){
// alert(1)
n--;
// console.log(n);
dong();
diandian();
}
/*左右键*/
$(".next").click(ne);
$(".prev").click(pr);
/*鼠标移入停止 鼠标移出继续*/
$("# lun").hover(function(){
clearInterval(time);
},function(){
time=setInterval(ne,1000);
});
/*自动轮播函数*/
var time=setInterval(ne,1000);
/*小圆点自动切换函数*/
function diandian(){
if(n==size-1){
$(".nav_item").eq(0).addClass('active').siblings().removeClass('active');
}
else{
$(".nav_item").eq(n).addClass('active').siblings().removeClass('active');
}
}
/*运动函数*/
function dong(){
if(n==size){
$(".img").css('left',0);
n = 1;
}
if(n==-1){
n=size-2;
}
$(".img").stop().animate({left:-n*200},500);
}
/*点击小圆点切换函数*/
$('.nav_item').hover(function(){
// alert(1);
var index=$(this).index();
n=index;
// console.log(index);
dong();
$(".nav_item").eq(index).addClass('active').siblings().removeClass('active');
});
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
img{
width: 200px;
height: 150px;
}
.img{
width: 20001px;
position: absolute;
}
.img_item{
float: left;
}
#lun{
width: 200px;
height: 150px;
border: 1px solid saddlebrown;
overflow: hidden;
margin: 10px auto;
position: relative;
}
.btn{
position: absolute;
top: 75px;
}
.next{
right: 0;
}
.prev{
left: 0;
}
.nav{
position: absolute;
/*border: 1px solid turquoise;*/
left: 45px;
bottom: 10px;
}
.nav_item{
width: 20px;
height: 20px;
border-radius: 50%;
display: inline-block;
margin-left: 5px;
background: white;
text-align: center;
line-height: 20px;
}
.nav:first-child{
margin-left: 0;
}
.nav_item.active{
background: rosybrown;
} .nav_item{
cursor: pointer;
}
</style>
<script src="jquery-1.8.3.js"></script>
</head>
<body>
<div id="lun">
<!--图-->
<ul class="img">
<li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/2.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/3.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/4.jpg" alt=""/></a></li>
<li class="img_item"><a href="javascript:;"><img src="img/1.jpg" alt=""/></a></li>
</ul>
<!--下标-->
<ul class="nav">
<li class="nav_item active">1</li>
<li class="nav_item">2</li>
<li class="nav_item">3</li>
<li class="nav_item">4</li>
</ul>
<!--左右键-->
<button class="btn prev"><</button>
<button class="btn next">></button>
</div>
<script>
var n=0;
var size=$(".img_item").size();
/*右键函数*/
function ne(){
// alert(1)
n++;
// console.log(n);
dong();
diandian();
}
/*左键函数*/
function pr(){
// alert(1)
n--;
// console.log(n);
dong();
diandian();
}
/*左右键*/
$(".next").click(ne);
$(".prev").click(pr);
/*鼠标移入停止 鼠标移出继续*/
$("# lun").hover(function(){
clearInterval(time);
},function(){
time=setInterval(ne,1000);
});
/*自动轮播函数*/
var time=setInterval(ne,1000);
/*小圆点自动切换函数*/
function diandian(){
if(n==size-1){
$(".nav_item").eq(0).addClass('active').siblings().removeClass('active');
}
else{
$(".nav_item").eq(n).addClass('active').siblings().removeClass('active');
}
}
/*运动函数*/
function dong(){
if(n==size){
$(".img").css('left',0);
n = 1;
}
if(n==-1){
n=size-2;
}
$(".img").stop().animate({left:-n*200},500);
}
/*点击小圆点切换函数*/
$('.nav_item').hover(function(){
// alert(1);
var index=$(this).index();
n=index;
// console.log(index);
dong();
$(".nav_item").eq(index).addClass('active').siblings().removeClass('active');
});
</script>
</body>
</html>