js implements mouse in and out card switching content

js implements mouse in and out card switching content

This article shares the specific code of js to realize the content switching of the mouse in and out of the card for your reference. The specific content is as follows

Case dynamic effect diagram:

HTML code:

<div class="sports-purple">
   <div class="all">
    
    <!-- Contents -->
    <div class="content">
     
     <div class="first-block">
      <!-- Sidebar for content -->
      <div class="aside">
       <h2>Categories</h2>
       <ul class="lis">
        <li class="sna">
         <a href="#">Sneakers</a>
         <div id="sub">
           <div><a href="#">Running Shoes</a></div>
           <div><a href="#">Basketball Shoes</a></div>
           <div><a href="#">Soccer Shoes</a></div>
           <div><a href="#">Hiking Shoes</a></div>
           <div><a href="#">Skateboarding Shoes</a></div>
           <div><a href="#">Dance shoes</a></div>
           <div><a href="#">Tennis Shoes</a></div>
           <div><a href="#">Cycling Shoes</a></div>
           <div><a href="#">Walking Shoes</a></div>
           <div><a href="#">Golf Shoes</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Sports Clothing</a>
         <div id="sup">
           <div><a href="#">Jackets</a></div>
           <div><a href="#">Base Layers</a></div>
           <div><a href="#">Shirts</a></div>
           <div><a href="#">Sets/Suits</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Cycling</a>
         <div id="cyc">
           <div><a href="#">Bicycle</a></div>
           <div><a href="#">Bicycle Parts</a></div>
           <div><a href="#">Bicycle Accessories</a></div>
           <div><a href="#">Bicycle Repair Tools</a></div>
           <div><a href="#">Cycling Clothings</a></div>
           <div><a href="#">Cycling Shoes</a></div>
           <div><a href="#">Electric Bicycle</a></div>
           <div><a href="#">Electric Bicycle Part</a></div>
           <div><a href="#">Self Balance Scooters</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Finshing</a>
         <div id="fin">
           <div><a href="#">Fishing Rods</a></div>
           <div><a href="#">Fishing Reels</a></div>
           <div><a href="#">Rod Combo</a></div>
           <div><a href="#">Fishing Lures</a></div>
           <div><a href="#">Fishing Lines</a></div>
           <div><a href="#">Fishhooks</a></div>
           <div><a href="#">Fishing Tackle Boxes</a></div>
           <div><a href="#">Fishing Float</a></div>
           <div><a href="#">Fishing Net</a></div>
           <div><a href="#">Fishing Rope</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Hunting</a>
         <div id="hun">
           <div><a href="#">Bow & Arrow</a></div>
           <div><a href="#">Hunting Optics</a></div>
           <div><a href="#">Hunting Cameras</a></div>
           <div><a href="#">Weapon Lights</a></div>
           <div><a href="#">Hunting Bags & Holsters</a></div>
           <div><a href="#">Hunting Knife</a></div>
           <div><a href="#">Hunting Lights</a></div>
           <div><a href="#">Hunting Decoy</a></div>
           <div><a href="#">Hunting Gun Accessories</a></div>
           <div><a href="#">Scope Mounts & Accessories</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Camping & Hiking</a>
         <div id="cam">
           <div><a href="#">Tents</a></div>
           <div><a href="#">Sun Shelter</a></div>
           <div><a href="#">Sleeping Bags</a></div>
           <div><a href="#">Climbing Bags</a></div>
           <div><a href="#">Outdoor Stoves</a></div>
           <div><a href="#">Outdoor Tablewares</a></div>
           <div><a href="#">Picnic Bags</a></div>
           <div><a href="#">Water Bags</a></div>
           <div><a href="#">Camping Mat</a></div>
           <div><a href="#">Outdoor Lighting</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Fitness & Body Building</a>
         <div id="fit">
           <div><a href="#">Fitness Equipments</a></div>
           <div><a href="#">Outdoor Fitness Equipment</a></div>
           <div><a href="#">Boxing</a></div>
           <div><a href="#">Yoga</a></div>
           <div><a href="#">Gymnastics</a></div>
           <div><a href="#">Martial Arts</a></div>
           <div><a href="#">Weight Lifting</a></div>
           <div><a href="#">Weight Lifting Gloves</a></div>
           <div><a href="#">Fitness Gloves</a></div>
           <div><a href="#">Dance shoes</a></div>
         </div>
        </li>
        <li class="sna">
         <a href="#">Musical Instruments</a>
         <div id="mus">
           <div><a href="#">Guitar</a></div>
           <div><a href="#">Guitar Parts & Accessories</a></div>
           <div><a href="#">Violin</a></div>
           <div><a href="#">Violin Parts & Accessories</a></div>
           <div><a href="#">Woodwind Instruments</a></div>
           <div><a href="#">Percussion Instruments</a></div>
           <div><a href="#">Instrument Bags & Cases</a></div>
           <div><a href="#">Brass Instruments</a></div>
           <div><a href="#">Keyboard Instruments</a></div>
         </div>
        </li>
       </ul>
       
       <div class="flip">
        <a href="#"class="page pagedown">
         <img src="../images/arrow.png">
        </a>
        <a href="#"class="page pageup">
         <img src="../images/arrow.png">
        </a>
        <div class="tail">
         1/3
        </div>
       </div>
      </div>
      
     </div>
 
 
    </div>
 
   </div>
 
  </div>
 
</div>

CSS:

*{
 margin:0;
 padding:0;
}
a{
 text-decoration: none;
}
li{
 list-style: none;
}
 
.sports-purple{
 width: 100%;
 background-color: #EEEEEE;
 position: relative;
 padding-top: 10px;
}
 
/* Start of content sidebar style */
.first-block{
 width: 100%;
 height: 500px;
}
.aside{
 width: 280px;
 height: 465px;
 background-color: #FFFFFF;
 margin-left: 150px;
}
.aside h2{
 color: #a059cb;
 text-align: left;
 line-height: 60px;
 border-bottom: 1px solid #A059CB;
 font-weight: 400;
 font-size: 18px;
 padding: 0 20px;
}
.lis li{
 border-bottom: 1px solid #EEEEEE;
 line-height: 40px;
 height: 40px;
 margin: 0 20px 0 20px;
}
.lis li a{
 color: #000000;
 font-size: 13px;
}
.list a:hover,.lis li a:hover{
 color: #FF4500;
 text-decoration: underline;
}
 
.flip{
 margin: 20px 0 20px 0px;
 line-height: 30px;
}
.flip .pagedown{
 width: 30px;
 height: 30px;
 border-radius: 4px;
 display: inline-block;
 border: 1px solid #a5a5a5;
 position: relative;
 left: 20px;
 overflow: hidden;
 margin-bottom: 20px;
}
.flip .pagedown img{
 position: absolute;
 left: 10px;
 top: 13px;
}
.flip .pageup{
 width: 30px;
 height: 30px;
 border-radius: 4px;
 display: inline-block;
 border: 1px solid #a5a5a5;
 position: relative;
 left: 40px;
 overflow: hidden;
 margin-bottom: 20px;
}
.flip .pageup img{
 position: absolute;
 left: -30px;
 top: -32px;
}
.flip .tail{
 float: right;
 margin-right: 130px;
 font-size: 12px;
}
 
#sub, #sup, #cyc,
#fin, #hun, #cam, #fit, #mus
 width: 300px;
 height: 403px;
 position: absolute;
 left: 400px;
 top: 70px;
 font-size: 13px;
 border: 1px solid #A059CB;
 background-color: #FFFFFF;
 z-index: 10;
 display: none;
}
.aside li:hover{
 border-left: 4px solid #A059CB;
 border-top: 1px solid #A059CB;
 border-bottom: 1px solid #A059CB;
 padding-left: 10px;
 margin-left: 20px;
 background-color: #FFFFFF;
}
 
#sub div,#sup div,
#cyc div,#fin div,
#hun div,#cam div,#fit div,
#mus div{
 margin-left: 20px;
}

js code:

// Get li according to class name
var lis = document.getElementsByClassName("sna");
 
//Loop through the li tags with class name sna for(var i = 0;i<lis.length;i++){
 //Register mouse move event for li lis[i].onmouseover = function(){
  /* this: li with class name sna */
  //console.log(this);
  /* this.children: Get the child elements under the li tag*/
  // console.log(this.children);
  var next = this.children;
  //next[1]: Among the two sub-elements under li, the subscript of the label of the element to be displayed is 1
  next[1].style.display = "block";
 };
 //Register mouse out event for li lis[i].onmouseout = function(){
  var next = this.children;
  next[1].style.display = "none";
 };
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • js mouse click button to switch pictures-pictures automatically switch-click left and right buttons to switch special effects code
  • JS switches pictures when the mouse moves over them
  • A simple js mouse over switching effect
  • JS+DIV method to achieve the effect of switching layers by mouse over
  • js to achieve the effect of mouse wheel scrolling to switch pages (similar to the 360 ​​default page scrolling switching effect)
  • js mouse click picture switching effect code sharing
  • js implements the method of switching pictures by dragging the mouse
  • js mouse click picture switching effect implementation code
  • JS+DIV example code to achieve the effect of switching layers when the mouse passes over
  • JavaScript simple method to switch pictures by moving the mouse

<<:  An article to deal with Mysql date and time functions

>>:  Docker pull image and tag operation pull | tag

Recommend

Detailed explanation of the difference between in and exists in MySQL

1. Prepare in Advance For your convenience, I cre...

Use elasticsearch to delete index data regularly

1. Sometimes we use ES Due to limited resources o...

How to install nginx in docker and configure access via https

1. Download the latest nginx docker image $ docke...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

How to find the my.ini configuration file in MySQL 5.6 under Windows

Make a note so you can come back and check it lat...

How does MySQL achieve master-slave synchronization?

Master-slave synchronization, also called master-...

Summary of Node.js service Docker container application practice

This article will not explain the use and install...

Multiple methods to modify MySQL root password (recommended)

Method 1: Use the SET PASSWORD command MySQL -u r...

A very detailed tutorial on installing rocketmq under Docker Desktop

Install Docker Desktop Download address: Docker D...

Solution for front-end browser font size less than 12px

Preface When I was working on a project recently,...

Detailed explanation of CSS3 to achieve responsive accordion effect

I recently watched a video of a foreign guy using...

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

Things to note when writing self-closing XHTML tags

The img tag in XHTML is so-called self-closing, w...