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 MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...

The use of mysql unique key in query and related issues

1. Create table statement: CREATE TABLE `employee...

Solve the problem after adding --subnet to Docker network Create

After adding –subnet to Docker network Create, us...

Introduction to deploying selenium crawler program under Linux system

Table of contents Preface 1. What is selenium? 2....

Problems with join queries and subqueries in MySQL

Table of contents Basic syntax for multi-table jo...

React and Redux array processing explanation

This article will introduce some commonly used ar...

CentOS uses local yum source to build LAMP environment graphic tutorial

This article describes how to use the local yum s...

A brief discussion on the use and analysis of nofollow tags

Controversy over nofollow There was a dispute bet...

How to modify the root password of mysql under Linux

Preface The service has been deployed on MySQL fo...

An article to help you thoroughly understand position calculation in js

Table of contents introduction scroll Element.scr...

How to solve the mysql insert garbled problem

Problem description: When inserting Chinese chara...

MySQL installation and configuration methods and precautions under Windows platform

2.1、msi installation package 2.1.1、Installation I...

CentOS 7 set grub password and single user login example code

There are significant differences between centos7...