The image carousel template type of jquery.

Source: Internet
Author: User

The image carousel template type of jquery.
Let's talk about several important events.
J
The jQuery on () method is officially recommended to bind events.
$ (Selector). on (event, childSelector, data, function, map) +


The off () method can be used to remove events bound to on.
For example: $ ("p"). on ("click", function (){
Certificate (this).css ("background-color", "pink ");
});
$ ("Button"). click (function (){
$ ("P"). off ("click ");




Animate (params, [duration], [easing], [callback])
A function used to create a custom animation.
The key to this function is to specify the animation form and result style attribute object. Each attribute in this object represents a changeable style attribute (such as "height", "top", or "opacity "). Note: All specified attributes must be in the camel format. For example, margin-left must be replaced by marginLeft.




Stop ([clearQueue], [gotoEnd])
Stops all animations that are running on the specified element.
If there are animations waiting for execution in the queue (and clearQueue is not set to true), they will be executed immediately








$ (Function (){
Var loopTime = 3000, // sets the carousel time.
AnimTime = 500; // sets the animation playing time.

Var sliderPlayer = $ ('. sliderPlayer '),
SliderHolder = $ ('. sliderHolder '),
SliderDiv = $ ('. sliderDiv '),
SliderBtnSpans = $ ('. sliderBtn span '),
SliderPre = $ ('btnpre '),
SliderNext = $ ('btnnext ');


Var Width = sliderPlayer. width (),
Height = sliderPlayer. height (),
Len = sliderDiv. width (Width). height (Height). length;


SliderHolder. width (Width * len). height (Height );

Var I = 0;
Function sliderToNext () {// This is the main function of carousel.
If (I> = len-1 ){
Var LastDiv = $ (". sliderDiv: last"). remove (); // get the last moving div and remove it.
SliderHolder. prepend (LastDiv); // put the obtained div at the beginning of the whole
SliderHolder.css ('left', '0'). stop (). animate ({"left":-(Width) + "px"}, animTime,
// The current order is 4123. Display 1, that is, the second one.
Function (){
Var firstDiv = sliderHolder. find ('. sliderDiv: first'). remove (); // obtain the first one, that is, 4, and then remove
SliderHolder.append(firstDiv).css ("left", "0"); // the current order is 1234 to display the original 1
});
I = 0;
} Else {
++ I;
SliderHolder. stop (). animate ({"left" :(-Width * I) + "px"}, animTime); // gradually backward
}
SliderBtnSpans. removeClass ("cur"). eq (I). addClass ("cur"); // The following Vertex
}


Var t = setInterval (sliderToNext, loopTime); // you can specify a timer for carousel.


SliderBtnSpans. each (function (index, element) {// This is when the mouse is placed on the following four buttons to stop and play away
$ (This). on ("mouseenter", function () {// when the mouse passes
I = index-1; // change the specified value
ClearInterval (t); // disable the timer
SliderToNext (); // continue Function
}). On ("mouseout", function () {// when the mouse is removed
T = setInterval (sliderToNext, loopTime); // start the timer again
});
});

SliderPlayer. find ('. btnpre'). click (function (event) {// The effect of the forward button
If (I> 0) I = I-2;
Else I = len-2;
SliderToNext ();
});
$ ('. BtnNext'). click (function (event) {// backward results
SliderToNext ();
});


})






The following html
<Div class = "sliderPlayer">
<Div class = "sliderHolder">
<Div class = "sliderDiv"> <a href = "#"> </a> </div>
<Div class = "sliderDiv"> <a href = "#"> </a> </div>
<Div class = "sliderDiv"> <a href = "#"> </a> </div>
<Div class = "sliderDiv"> <a href = "#"> </a> </div>
<A class = "clear"> </a>
</Div>
<A href = "#" class = "BtnPre"> </a>
<A class = "BtnNext"> </a>
<Div class = "sliderBtn">
<Span class = "cur"> </span>
<Span> </span>
<Span> </span>
<Span> </span>
</Div>
</Div>






Css layout




. SliderPlayer {
Margin: 0 auto;
Width: 1170px;
Height: 403px;
Position: relative;
Overflow: hidden;
}
. SliderHolder {
Height: 406px;
Position: absolute;
Top: 0px;
}
. SliderDiv {
Float: left;
}
. SliderHolder img {
Display: block;
Margin: 0;
Padding: 0;
}
. SliderBtn {
Position: absolute;
Bottom: 20px;
Left: 500px;
}
Span. cur {
Background: # fff;
}
. BtnPre {
Position: absolute;
Left: 0px;
Top: 150px;
Background-image: url (../images/tujian.png );
Background-position:-61px 50%;
Height: 60px;
Width: 50px;
}
. BtnNext {
Position: absolute;
Right: 0px;
Top: 150px;
Background-image: url (../images/tujian.png );
Background-position:-1184px 50%;
Height: 60px;
Width: 50px;
}
. SliderBtn {
Position: absolute;
Left: 525px;
Bottom: 12px;
Text-align: right;
}
. SliderBtn span {
Display: inline-block;
Margin: 0 5px;
Width: 14px;
Height: 14px;
Background: # fff;
Cursor: pointer;
Border-radius: 50%;
}
Span. cur {
Background: # 1b489e;
}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.