js 下拉菜单案例

2021-02-10 11:16

阅读:509

YPE >

标签:微博   tom   utf-8   script   one   mouseover   set   log   sel   

html>

    
    
    
    Document
    
        * {
            margin: 0;
            padding: 0;
        }
        
        li {
            list-style-type: none;
        }
        
        a {
            text-decoration: none;
            font-size: 14px;
        }
        
        .nav {
            margin: 100px;
        }
        
        .nav>li {
            position: relative;
            float: left;
            width: 80px;
            height: 41px;
            text-align: center;
        }
        
        .nav li a {
            display: block;
            width: 100%;
            height: 100%;
            line-height: 41px;
            color: #333;
        }
        
        .nav>li>a:hover {
            background-color: #eee;
        }
        
        .nav ul {
            display: none;
            position: absolute;
            top: 41px;
            left: 0;
            width: 100%;
            border-left: 1px solid #FECC5B;
            border-right: 1px solid #FECC5B;
        }
        
        .nav ul li {
            border-bottom: 1px solid #FECC5B;
        }
        
        .nav ul li a:hover {
            background-color: #FFF5DA;
        }
    

    
            
  •             微博
                
                      
    •                     私信
                      
                      
    •                     评论
                      
                      
    •                     @我
                      
                  
              
              
    •             微博
                  
                        
      •                     私信
                        
                        
      •                     评论
                        
                        
      •                     @我
                        
                    
                
                
      •             微博
                    
                          
        •                     私信
                          
                          
        •                     评论
                          
                          
        •                     @我
                          
                      
                  
                  
        •             微博
                      
                            
          •                     私信
                            
                            
          •                     评论
                            
                            
          •                     @我
                            
                        
                    
                
                
                    //  1 获取元素
                    var nav = document.querySelector(‘.nav‘);
                    var lis = nav.children; //得到 4个 li
                    // console.log(lis);
                    // 循环注册事件
                    for (var i = 0; i 
                        lis[i].onmouseover = function() {
                            this.children[1].style.display = ‘block‘;
                        }
                        lis[i].onmouseout = function() {
                            this.children[1].style.display = ‘none‘;
                        }
                    }
                

            js 下拉菜单案例

            标签:微博   tom   utf-8   script   one   mouseover   set   log   sel   

            原文地址:https://www.cnblogs.com/ericblog1992/p/13052513.html


            评论


            亲,登录后才可以留言!