JQuery implementation option linkage carousel effect [attached instance], jquery instance

Source: Internet
Author: User

JQuery implementation option linkage carousel effect [attached instance], jquery instance

<! Doctype html> 

CSS

* {Border: none; margin: 0; padding: 0; list-style: none; outline: none;} html, body {width: 100%; height: 100% ;} /* method 2 */body {display: flex; align-items: center;/***** horizontal center *****/justify-content: center; /* vertical center */}. parent {width: 750px; height: 400px;/* method 1 * // * margin: 0 auto; * // * position: relative; * // * top: 50%; * // * margin-top:-200px; * //}/* carousel */. top p {width: 90%; margin: 0 auto ;}. top p a {display: inline-block; line-height: 30px; width: 23%; padding: 10px 0; text-align: center; text-decoration: none; border: 2px solid transparent; color: slategray ;}. top p. selected {border: 2px solid # e4393c; color: # e4393c;}/* image */. fours {width: pixel PX; margin: 0 auto; height: 300px; position: relative; margin-top: 30px ;}. fours a {position: absolute ;}

JS

Define variables and timers. variables are equivalent to indexes in eq (index). Automatic carousel is possible. The key is how to correspond to the desired carousel screen when you move the mouse into the tab area,

Method: stop the timer, get the subscript of the current tab, and match the corresponding carousel screen.

Var a = 0; var t = null; $ (function () {$ ('. fours> a: not (: first-child )'). hide (); t = setInterval ("autoMove ()", 2000); // enter the slideshow stop $ ('. parent '). hover (function () {clearInterval (t)}, function () {t = setInterval ("autoMove ()", 2000 );}); // The image changes accordingly when you move the cursor to the corresponding option $ (". top p> "). hover (function () {clearInterval (t); var num = $ (this ). index (); showThis (num); // console. log (num) ;})}; function autoMove () {a ++; if (a >= 4) {a = 0 ;} play ();} function play (a) {$ ('. fours> '). filter (": visible "). fadeOut (1, 500 ). parent (). children (). eq (). fadeIn (1000); $ ('. top p '). eq (). addClass ("selected "). siblings (). removeClass ("selected");} // function showThis (sum) {$ (". fours> "). eq (sum ). fadeIn (1000 ). siblings (). fadeOut (500); $ (". top p "). eq (sum ). addClass ("selected "). siblings (). removeClass ("selected ");}

The above jQuery implementation option linkage carousel effect [attached instance] is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the customer's house.

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.