css3-pointer-events_demo

  该demo定义了一个菜单,点击了一次之后就不能再点击,另外其中也用到了flex布局,可直接将代码复制运行即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<html>
  <head>
    <meta name="generator"
    content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
    <title></title>
    <meta charset="utf-8" />
    <style>
        *{
            margin:0px;
            padding:0px;
        }
        li{
            list-style:none;
        }
        .menu{
            display:flex;
                flex-flow: row nowrap;
                width:800px;
                height:30px;
                background:gray;
                margin:20px;
        }
        .menu li{
            width:20%;
            height:100%;
            margin-left:5px;
            background:green;
            text-align:center;
            color:#fff;
            line-height:30px;
            cursor:pointer;
            -moz-user-select:none;
        }
        .menu li:nth-child(1){
            margin:0px;
        }
        .menu li:hover{
                color:#fff;
                background:#f00;
        }
        .pointer{
            pointer-events:none;
        }
    </style>
  </head>
  <body>
    <ul class="menu">
        <li>首页</li>
        <li>产品中心</li>
        <li>新闻中心</li>
        <li>公司简介</li>
        <li>联系我们</li>
    </ul>
    <div id="divContent"></div>
    <script>
    var divContent=document.getElementById("divContent");
        document.getElementsByTagName("ul")[0].addEventListener("click",function(e){
            var currentObj=e.target;
            if(currentObj.tagName.toLowerCase()=="li"){
                var childList=document.getElementsByTagName("ul")[0].childNodes;
                for(var i=0;i<childList.length;i++){
                    childList[i].className="";
                }
                currentObj.className=" pointer";
                divContent.innerHTML=currentObj.innerHTML;
                console.log(divContent.innerHTML);
            }
        })
    </script>
  </body>
</html>

  

posted @   Ben Chan  阅读(150)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示