I have encountered jQuery to implement automatic list scrolling. This image carousel has the same principle and only has some minor differences, the sequence number of the current image must be displayed in the lower right corner of the image as follows:
Let's take a look at the html code and the corresponding css code:
The Code is as follows:
The Code is as follows:
# ScrollPics {
Height: 150px;
Width: 100%;
Margin-bottom: 10px;
Overflow: hidden;
Position: relative;
}
. Num {
Position: absolute;
Right: 5px;
Bottom: 5px;
}
# ScrollPics. num li {
Float: left;
Color: # FF7300;
Text-align: center;
Line-height: 16px;
Width: 16px;
Height: 16px;
Cursor: pointer;
Overflow: hidden;
Margin: 3px 1px;
Border: 1px solid # FF7300;
Background-color: # fff;
}
# ScrollPics. num li. on {
Color: # fff;
Line-height: 21px;
Width: 21px;
Height: 21px;
Font-size: 16px;
Margin: 0 1px;
Border: 0;
Background-color: # FF7300;
Font-weight: bold;
}
Use absolute positioning to set the position of num in the list, and set the relevant style for li. on indicates that the style category of li in the number list corresponding to the image is displayed.
The following is the js Code:
The Code is as follows:
// Rolling Advertisement
Var len = $ (". num> li"). length;
Var index = 0; // image serial number
Var adTimer;
$ (". Num li"). mouseover (function (){
Index = $ (". num li"). index (this); // you can call this operation to retrieve the index of li.
ShowImg (index );
}). Eq (0). mouseover ();
// Slide in to stop the animation and slide out to start the animation.
$ ('# ScrollPics'). hover (function (){
ClearInterval (adTimer );
}, Function (){
AdTimer = setInterval (function (){
ShowImg (index)
Index ++;
If (index = len) {// go to the first image after the last image
Index = 0;
}
},3000 );
}). Trigger ("mouseleave ");
Function showImg (index ){
Var adHeight = $ ("# scrollPics> ul> li: first"). height ();
$ (". Slider"). stop (true, false). animate ({
"MarginTop":-adHeight * index + "px" // you can change the value of the marginTop attribute to achieve carousel effect.
},1000 );
$ (". Num li"). removeClass ("on ")
. Eq (index). addClass ("on ");
}