<! DOCTYPE html>
<meta charset= "UTF-8"/>
<title> Carousel </title>
<style>
body{
margin:0;
}
. Banner {
width:100%;
position:relative;
Overflow:hidden;
}
. Banner UL {
width:100%;
height:500px;
}
. Banner Li {
Float:left;
width:100%;
Position:absolute;
top:0;
left:0;
}
. Banner a {
Display:block;
}
. Banner img {
width:100%;
}
. Banner P {
width:105px;
height:20px;
Position:absolute;
bottom:10px;
left:50%;
Margin-left: -42px;
z-index:999;
}
. Banner span {
width:12px;
height:12px;
Display:block;
Float:left;
Margin:0 5px;
border:2px solid #7c7a7b;
border-radius:50%;
Background: #7c7a7b;
Cursor:pointer;
}
. banner. Active {
Background: #fff;
border:2px solid #97c62c;
}
. Banner a {
Position:absolute;
top:50%;
left:30px;
Z-index:11;
Cursor:pointer;
width:44px;
height:44px;
Margin-top: -24px;
Transform:rotate (45DEG);
-webkit-transform:rotate (45DEG);
-ms-transform:rotate (45DEG);
-o-transform:rotate (45DEG);
}
. prev {
border-bottom:2px solid #393F3B;
border-left:2px solid #393F3B;
}
. Banner. Next {
Left:auto;
right:30px;
border-top:2px solid #393F3B;
border-right:2px solid #393F3B;
}
. cur{
Z-index:2;
}
</style>
<body>
<div class= "banner" >
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<p>
<span class= "Active" ></span>
<span class= "" ></span>
<span class= "" ></span>
<span class= "" ></span>
</p>
<a class= "prev" href= "javascript:;" ></a>
<a class= "Next" href= "javascript:;" ></a>
</div>
<script src= "Js/jquery-1.9.1.min.js" ></script>
<script>
$ (function () {
var i = 0;
var iTimer = null;
var aLi = $ ('. Banner ul '). Find (' Li ');
var Aspan = $ ('. Banner P '). Find (' span ');
Add a click action to all spans
Aspan.click (function () {
i = $ (this). index ();
Console.log (i);
Fadefn ();
});
Click Prev, the picture shows the previous one;
$ ('. Prev '). Click (function () {
if (i > 0) {
i--;
Fadefn ();
}
});
Click Next, the picture shows the next one;
$ ('. Next '). Click (function () {
Console.log (i);
if (I < ali.size ()-1) {
i++;
Fadefn ();
}
});
Find all Li, clear all Li's class, add cur to the first Li, and change the transparency of Li; Add class to its next li;
function Fadefn () {
Ali.removeclass (). Hide ();
Ali.eq (i). addclass (' cur '). FadeIn (' slow ');
Aspan.removeclass ();
Aspan.eq (i). addclass (' active ');
}
function AutoPlay () {
i++;
I%= ali.size ();
Fadefn ();
}
ITimer = SetInterval (AutoPlay, 3000);
Mouse move to stop timer, mouse to move the start timer;
$ ('. Banner '). MouseOver (function () {
Clearinterval (ITimer);
$ ('. Prev '). Show ();
$ ('. Next '). Show ();
});
$ ('. Banner '). Mouseout (function () {
Clearinterval (ITimer); First stop, then open;
ITimer = SetInterval (AutoPlay, 3000);
$ ('. Prev '). Hide ();
$ ('. Next '). Hide ();
});
})
</script>
</body>
PC-side AD Carousel diagram