jquery Gets the current element index value usage instance _jquery

Source: Internet
Author: User
Tags setinterval

The example in this article tells JQuery to get the current element index value usage. Share to everyone for your reference. Specifically as follows:

Today in the promotion page of the image rotation effect, the bottom page number of the left side of the corresponding display picture description information, the effect is as follows:

Ideas:

When the page section is in the current state, the active style is added.

By obtaining the index value of Li class= "active", the corresponding picture description information is found, which is displayed.

Solve:

The result can be easily achieved by using the index () of jquery.

The code is as follows:

Html:

<div id= "Carousel" > <div id= "carouselimg" > <div id= "Imgcontainer" > <a href= "#" mce_href= "#" ></a> <a href=" # "mce_href=" # "></a> <a href=" # "MC e_href= "#" ></a> <a href= "#" mce_href= "#" ></a> <a H 
 ref= "#" mce_href= "#" ></a> </div> </div> <div id= "Carouseltitle" > <div class= "Carouseltext" > <span> </span> <span> </span> <span> </span& 
   Gt <span> </span> <span> </span> </div> <ul> <li><span>1</span 
   ></li> <li><span>2</span></li> <li><span>3</span></li> <li><span>4</span></li> <li><span>5</span></li> </ul> ;/div> </Div>

 

JavaScript:

<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" mce_src= "http://  
Ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js "></SCRIPT> <script type=text/javascript> var carousedata = [{index:0,link: "http://www.dangdang.com", Imgsrc: "1.jpg", Text: "Thousands of famous mobile phone 60 percent"}, {index:1,link: "http: Www.baidu.com ", imgsrc:" 2.jpg ", Text:" Test text 2 "}, {index:2,link:" http://www.google.com ", Imgsrc:" 3.jpg ", Text:" Test text 3 "}, {index:3,link:" http://www.soso.com ", Imgsrc:" Xf.jpg ", Text:" Test text 4 "}, {index:4,link:" Http://www.jb51.net ", 
IMGSRC: "Py.jpg", Text: "Test text 5"}]; 
 $ (document). Ready (function () {$ ("#imgcontainer a"). each (function (i) {$ (this). attr ("href", carousedata[i].link); 
  $ (this). Children ("img"). attr ("src", carousedata[i].imgsrc); 
  }); 
  $ (". Carouseltext span"). each (the function (i) {$ (this). Text (Carousedata[i].text); 
 }) SetInterval (function () {var li_index = $ ("#carouseltitle ul li"). Index ("#carouseltitle ul li.active") [0]); $ (". CarouseltexT span "). Hide (); 
  $ (". Carouseltext span"). EQ (Li_index). Show (); 
},10); 
});

 </script>

Here, I use setinterval, not 10ms to find it once.

The code also has a place to optimize.

I hope this article will help you with your jquery programming.

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.