Home > Web Front-end > JS Tutorial > JavaScript imitation Jingdong navigation left category navigation drop-down menu effect_javascript skills

JavaScript imitation Jingdong navigation left category navigation drop-down menu effect_javascript skills

WBOY
Release: 2016-05-16 15:08:30
Original
1644 people have browsed it

The example in this article shares with you a drop-down menu similar to the left category navigation of JD.com and Taobao Mall for your reference. The specific content is as follows

Rendering:

Implementation code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="gb2312">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <style>
   *{margin:0;padding:0;}
   .ul{position:relative;width:200px;height:auto;} 
   .ul li{height:24px;line-height:24px;border-bottom:1px solid #ddd;text-align:center;font-size:12px;}
   .ul li a{display:block;background:#fff;color:#000;text-decoration:none;}
   .ul li a:hover{display:block;background:#000;color:#fff;text-decoration:none;}
   .ul li div{display:none;width:400px; height:auto;position:absolute;top:0;left:200px; background:#000; color:#fff;}
   .ul li div dl dd{float:left; width:100px;}
   .ul .liname div{display:block;}
  </style>
  <script>
    window.onload=function(){
      var aLi=document.getElementsByTagName("li");
      for(var i=0;aLi.length>i;i++){
        aLi[i].i=i;
        aLi[i].onmouseover=function(){
          this.className="liname";
 
          var h1=this.i*25;
          var h2=this.getElementsByTagName("div")[0].offsetHeight;
          if(h2<h1){
            this.getElementsByTagName("div")[0].style.top=h1+'px';
          }
           
        }
        aLi[i].onmouseout=function(){
          this.className="";
        }
      }
    }
  </script>
</head>
<body>
  <ul class="ul">
    <li>
      <a href="">类别1</a>
      <div class="div">
        <dl>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
    </li>
    <li>
    <a href="">类别2</a>
      <div class="div">
        <dl>
          <dd>类别2</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
    </li>
    <li><a href="">类别3</a><div class="div">
        <dl>
          <dd>类别3</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
    <li><a href="">类别4</a><div class="div">
        <dl>
          <dd>类别4</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
    <li><a href="">类别5</a><div class="div">
        <dl>
          <dd>类别5</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
    <li><a href="">类别6</a><div class="div">
        <dl>
          <dd>类别6</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
    <li><a href="">类别7</a><div class="div">
        <dl>
          <dd>类别7</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
    <li><a href="">类别8</a><div class="div">
        <dl>
          <dd>类别8</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
          <dd>类别1</dd>
        </dl>
      </div>
      </li>
  </ul>
</body>
</html>
Copy after login

I hope this article will be helpful to everyone in learning javascript programming.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template