Javascript move the mouse up to the slider to follow the effect

Source: Internet
Author: User
First. Move the mouse to the corresponding category, and the red triangle below will automatically follow, slowly following. No matter how many. Javascriptcode: [javascript] functionchangeCoord (id, left) {$ $ (id). style. leftleft;} fu... Syntax

First.

 
 


Move the mouse to the corresponding category, and the red triangle below will automatically follow, slowly following.

No matter how many.

Javascript code:


[Javascript]
Function changeCoord (id, left ){
$ (Id). style. left = left;
}
 
Function $ (id ){
Return document. getElementById (id );
}
 
Function $ (id ){
Return document. getElementsByClassName (id) [0];
}
 
Function indexOf (arry, obj ){
For (var I = 0; I <arry. length; I ++ ){
If (obj = arry [I]) {
Return I;
}
};
}
 
Window. onload = function (){
// Register events for all the slide on the page
// Products-box-center parent container object

Var obj = document. getElementsByClassName ('products-box-Center ');
For (var I = 0; I Try {
Var base = obj [I]. getElementsByClassName ('products-box-center-title') [0]; // obtain the title of each item
Var elems = base. getElementsByClassName ('products-items-title ');
For (var j = 0; j Var elem = elems [j];
Elem. onmousemove = function (){
// Obtain the parent container of the current object
Var baseElem = this. parentElement. parentElement;
Var baseIndex = indexOf (obj, baseElem) + 1;

// Obtain the coordinates of the current object
Var left = this. offsetLeft;

// Obtain the corresponding slider object
Var slider =$ $ ('products-triangle-'+ baseIndex );

// Change the coordinate of the slider
Slider. style. left = left + "px ";
// Change the color of the current object and other objects
This. style. color = "red ";
// Obtain all elements under the current parent container
Var notes = this. parentElement. getElementsByClassName ('products-items-title ');
For (var k = 0; k If (this! = Notes [k])
Notes [k]. style. color = "#666 ";
}

};
}

}
Catch (e ){
Alert (e );
}
};
 
}

Function changeCoord (id, left ){
$ (Id). style. left = left;
}

Function $ (id ){
Return document. getElementById (id );
}

Function $ (id ){
Return document. getElementsByClassName (id) [0];
}

Function indexOf (arry, obj ){
For (var I = 0; I <arry. length; I ++ ){
If (obj = arry [I]) {
Return I;
}
};
}

Window. onload = function (){
// Register events for all the slide on the page
// Products-box-center parent container object
 
Var obj = document. getElementsByClassName ('products-box-Center ');
For (var I = 0; I Try {
Var base = obj [I]. getElementsByClassName ('products-box-center-title') [0]; // obtain the title of each item
Var elems = base. getElementsByClassName ('products-items-title ');
For (var j = 0; j Var elem = elems [j];
Elem. onmousemove = function (){
// Obtain the parent container of the current object
Var baseElem = this. parentElement. parentElement;
Var baseIndex = indexOf (obj, baseElem) + 1;

// Obtain the coordinates of the current object
Var left = this. offsetLeft;

// Obtain the corresponding slider object
Var slider =$ $ ('products-triangle-'+ baseIndex );

// Change the coordinate of the slider
Slider. style. left = left + "px ";
// Change the color of the current object and other objects
This. style. color = "red ";
// Obtain all elements under the current parent container
Var notes = this. parentElement. getElementsByClassName ('products-items-title ');
For (var k = 0; k If (this! = Notes [k])
Notes [k]. style. color = "#666 ";
}

};
}

}
Catch (e ){
Alert (e );
}
};

} Html code:


[Html]
 

Latest Product
Notebook
Digital audio and video
Accessories
Office Printing
 








  •  


    LG IPS237L-BN 23 inch IPS display



    ¥1299.00


  •  
     
 




 

Latest Product
Notebook
Digital audio and video
Accessories
Office Printing












  • LG IPS237L-BN 23 inch IPS display



    ¥1299.00










The above html is part. You can use the el expression to loop and try more...

It takes only one morning to complete...


 

Related Article

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.