zoukankan      html  css  js  c++  java
  • 导航栏图标切换:click事件,hover事件

    最近再做一个基于angular6的项目,导航栏需求:1、hover切换图标 2、click切换图标

    先用jquery实现功能,在在angular组件里面实现。

    demo如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>导航栏图标切换</title>
      <style>
        ul{
          background-color: #0f0f0f;
           50px;
        }
        li{
          height: 50px;
           50px;
          display: block;
          cursor: pointer;
        }
        .li1{
          background: url("./img/nav/h1.png") no-repeat;
        }
        .li2{
          background: url("./img/nav/b1.png") no-repeat;
        }
        .li3{
          background: url("./img/nav/v1.png") no-repeat;
        }
        .li4{
          background: url("./img/nav/m1.png") no-repeat;
        }
    
        .li1:hover{
          background: url("./img/nav/h0.png") no-repeat;
        }
        .li2:hover{
          background: url("./img/nav/b0.png") no-repeat;
        }
        .li3:hover{
          background: url("./img/nav/v0.png") no-repeat;
        }
        .li4:hover{
          background: url("./img/nav/m0.png") no-repeat;
        }
    
        .li1.selected{
          background: url("./img/nav/h0.png") no-repeat;
        }
        .li2.selected{
          background: url("./img/nav/b0.png") no-repeat;
        }
        .li3.selected{
          background: url("./img/nav/v0.png") no-repeat;
        }
        .li4.selected{
          background: url("./img/nav/m0.png") no-repeat;
        }
      </style>
      <script src="js/jquery.min.js"></script>
    </head>
    <body>
    <ul>
      <li class="li1"></li>
      <li class="li2"></li>
      <li class="li3"></li>
      <li class="li4"></li>
    </ul>
    <script>
        $(function(){
            $("li").click(function() {
                $(this).siblings('li').removeClass('selected');          // 删除其他兄弟元素的样式
                $(this).addClass('selected');                            // 添加当前元素的样式
            });
        });
    </script>
    </body>
    </html>
    

      

    明月装饰了你的窗子,你装饰了他的梦。
  • 相关阅读:
    可图性判定HavelHakimi定理
    并查集入门
    js数组和函数应用
    DOM用法及应用
    javascript基础知识
    表单
    PHP变量
    30天自制操作系统开发笔记——IDT中断描述符表
    《30天自制操作系统》学习笔记——汇编程序磁盘BIOS调用
    汇编指令: LGDT、LIDT、LLDT、LMSW、LOADALL、LOADALL286、LOCK、LODSB、LODSW、LODSD
  • 原文地址:https://www.cnblogs.com/zkkysqs/p/10066288.html
Copyright © 2011-2022 走看看