Seamless image scrolling

Source: Internet
Author: User
[Javascript]/* 2013-4-10 the simplest way to write the animation */$ (function () {vartime3000; // The interval at which the animation is played is vardhua_time500 in milliseconds; // The gap time of image rotation is millisecond varani... syntaxHighlighter. al [javascript]
/* Follow the simplest way of writing for Production */
$ (Function (){
Var time = 3000; // The animation playback interval is milliseconds.
Var dhua_time = 500; // The gap time of image rotation is millisecond
Var animate_pic; // defines the animation function
Var ul_li = ". gaga_pic ul li"; // obtain the image's parent node li
Var wid = $ (ul_li). width () + 10; // obtain the image width.
Var li_len = $ (ul_li). length; // obtain the number of images.
Var first_an = ". gaga_pic ul li: first"; // obtain the first li
Var last_an = ". gaga_pic ul li: last"; // obtain the last li
Var prev = "prev"; // click the previous button.
Var next = "next"; // click the next button
Var an_div_a = "# gaga a"; // click the element
Var an_bof = "# gaga"; // display the image box
Var min = 4; // The number of images must be greater than the number of images displayed in the box.
If (li_len> min) {// The number of images must be greater than the number of images displayed in the box before the animation can be executed
If (li_len = min + 1) {// prevents white space
$ (First_an ).css ("margin-left", wid); // you can specify the margin-left of the first image li.
} Else {
$ (Last_an). insertBefore (first_an); // Insert the last li to the end of the first li
}
Function run () {// Encapsulation
If (! $ (Ul_li). is (": animated") {// judge whether the animation is in progress
If (li_len = min + 1) {// prevents white space
$ (First_an). animate ({"margin-left": 0}, d1__time, function (){
$ (First_an). insertAfter (last_an); // Insert the first li to the end of the last li
$ (Ul_li). attr ("style", ""); // set the margin of li to 0.
$ (First_an ).css ("margin-left", wid );
});
} Else {
$ (First_an). animate ({"margin-left":-wid}, d1__time, function (){
$ (First_an). insertAfter (last_an); // Insert the first li to the end of the last li
$ (Ul_li). attr ("style", ""); // set the margin of li to 0.
});
};
};
};
$ (An_div_a). live ("click", function (){
If ($ (this). hasClass (next) {// determines whether to click the next one to display the previous one (forward)
Run ();
Return false; // prevent redirection
} Else if ($ (this). hasClass (prev) {// display the next one (back)
If (! $ (Ul_li). is (": animated") {// judge whether the animation is in progress
Function last_animte () {// Encapsulation
$ (Last_an). insertBefore (first_an); // Insert the last li to the end of the first li
$ (Ul_li). attr ("style ","");
};
If (li_len = min + 1) {// prevents white space
Last_animte ();
$ (First_an). animate ({"margin-left": wid}, d1__time );
} Else {
$ (First_an). animate ({"margin-left": wid}, d1__time, function (){
Last_animte ();
});
};
};
Return false; // prevent redirection
};
});
// Automatic playback
$ (An_bof). hover (function (){
ClearInterval (animate_pic); // clear the animation
}, Function (){
Animate_pic = setInterval (run, time); // execute the animation
}). Trigger ("mouseleave ");
} Else {
$ (First_an ).css ("margin-left", wid); // If the currently displayed image is smaller than the image to be displayed in the displayed box, no animation is executed.
};
});

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.