Perfect realization of eight kinds of JS Focus carousel (above) _javascript skills

Source: Internet
Author: User
Tags setinterval

This article is divided into the upper and lower parts for everyone to share the JS focus of eight kinds of classic results, for your reference, the specific contents are as follows

Basic layout:

<div id= "box" >
 <ul id= "ul" >
  <li style= ' Display:block; ' ></li> <li></li
  >
  <li></li> <li></li>
  <li></li>
 </ul>
 <ol id= '" Ol ' >
  <li class= ' active ' >1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
 </ol>
 </div>

--------------------------------------------------------------------------------

1. General Focus Chart

Window.onload=function () {
   var Oul=document.getelementbyid (' ul ');
   var ali_u=oul.getelementsbytagname (' Li ');
   var Ool=document.getelementbyid (' ol ');
   var ali_o=ool.getelementsbytagname (' Li ');
   for (Var i=0;i<ali_o.length;i++) {
    ali_o[i].index=i;
    Ali_o[i].onmouseover=function () {for
     (var i=0;i<ali_o.length;i++) {
      ali_o[i].classname= ';
      Ali_u[i].style.display= ' None ';
     }
     This.classname= ' active ';
     Console.log (Ali_o[this.index]);
     ali_u[this.index].style.display= ' block ';}}
  

Effect Picture: Tullo

2. Fade effect

var Oul=document.getelementbyid (' ul ');
var ali_u=oul.getelementsbytagname (' Li ');
var Ool=document.getelementbyid (' ol ');
var ali_o=ool.getelementsbytagname (' Li ');

for (Var i=0;i<ali_o.length;i++) {
 ali_o[i].index=i;
 Ali_o[i].onmouseover=function () {for
   (var i=0;i<ali_o.length;i++) {
    ali_o[i].classname= ';
    Ali_u[i].style.display= ' None ';
    Ali_u[i].style.filter= ' alpha (opacity=0) ';
    ali_u[i].style.opacity=0;
   }
   This.classname= ' active ';
   ali_u[this.index].style.display= ' block ';
   Startmove (ali_u[this.index],{opacity:100});}


Effect Chart:

3. Scroll up effect:

var Oul=document.getelementbyid (' ul ');
var ali_u=oul.getelementsbytagname (' Li ');
var Ool=document.getelementbyid (' ol ');
var ali_o=ool.getelementsbytagname (' Li ');
var liheight=ali_u[0].offsetheight;

for (Var i=0;i<ali_o.length;i++) {
 ali_o[i].index=i;
 Ali_o[i].onmouseover=function () {for
  (var i=0;i<ali_o.length;i++) {
   ali_o[i].classname= ';

   This.classname= ' active ';

   Startmove (Oul,{top:-this.index*liheight});
  }


Effect Chart:


4. Rolling up and down periodically:

Window.onload=function () {var obox=document.getelementbyid (' box ');
 var Oul=document.getelementbyid (' ul ');
 var ali_u=oul.getelementsbytagname (' Li ');
 var Ool=document.getelementbyid (' ol ');
 var ali_o=ool.getelementsbytagname (' Li ');
 var liheight=ali_u[0].offsetheight;
  var inow=0;//current index var timer=null;//timer for (var i=0;i<ali_o.length;i++) {ali_o[i].index=i;

    Ali_o[i].onmouseover=function () {for (Var i=0;i<ali_o.length;i++) {ali_o[i].classname= ';
    This.classname= ' active ';

    Establish a relationship: very important inow=this.index;
   Startmove (Oul,{top:-this.index*liheight});
 }
  };

 Open Timer timer=setinterval (torun,2000);
 Obox.onmouseover=function () {clearinterval (timer);
 };
 Obox.onmouseout=function () {timer=setinterval (torun,2000);
 };
  Timing function Torun () {if (inow==ali_o.length-1) {inow=0;
  }else{inow++;
  for (Var i=0;i<ali_o.length;i++) {ali_o[i].classname= ';
  } ali_o[inow].classname= ' active ';
 Startmove (Oul,{top:-inow*liheight});

}
}; 

Effect Chart:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud Habitat community, we continue to pay attention to more exciting focus of the rotation map.

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.