jQuery单选组美化特效

 需求:根据数据动态生成单选组

代码:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>jQuery单选选中美化特效</title>
 6 </head>
 7 <body>
 8     <style type="text/css">
 9     h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}
10     @charset 'utf-8';
11     html,body {
12              background: #b1afaf;
13         }
14         .wrap {
15             width: 200px;
16             height: 100px;
17             background: #ffffff;
18             margin: 5px ;
19             box-shadow: 1px 1px 10px #333,-1px -1px 10px #333;
20             cursor: pointer;
21             /* line-height: 20px; */
22             overflow: hidden;
23             /* text-overflow: ellipsis; */
24             white-space: nowrap;
25             border: 5px solid  #eef2e6;
26             float: left;
27         }
28         .wrap div {
29             display: contents;
30             width: 200px;
31             height: 100px;
32             background: #7dbee6;
33             padding-top: 1px;
34         }
35         /*#menu {
36             height: 300px;
37             width: 200px;
38             background: #ffffff;
39             float: left;
40             margin-top: 25px;
41             box-shadow: 1px 1px 10px #333, -1px -1px 10px #333;
42         }*/
43         /*#user {
44             width: 500px;
45             height: auto;
46             float: left;
47             margin-top: 20px;
48         }*/
49 </style>
50 <div>
51 <!-- <div id ='menu'></div> -->
52 <div id ='user'></div>
53 </div>
54 <script src="js/jquery.js"></script>
55 <script>
56     $("#user").empty()
57     $(function() {
58         let arr =[0,1,2,3,4,5,6,7,8];
59         var bo = document.getElementById('user');
60         for(var i=0; i<arr.length; i++){
61             var div = document.createElement('div');
62                 div.innerHTML = '<div><h1>'+arr[i]+'</h1></div>';
63                 div.className = "wrap";
64                 div.setAttribute("switch","off");
65                 div.setAttribute("D",arr[i]);
66                 div.onclick = function(){
67                     if ($(this).attr("switch") == "off") {
68                         $(this).children("div").css({
69                             "display" : "block",
70                             "color" : "#FFF"
71                         }),
72                         $(this).attr("switch","on");
73                         $(this).siblings().attr("switch","off");
74                         $(this).siblings().children("div").css({
75                             "display" : "contents",
76                             "color" : "#000"
77                         })
78                     }else {
79                         $(this).children("div").css({
80                             "display" : "contents",
81                             "color" : "#000"
82                         }),
83                         $(this).attr("switch","off");
84                     }
85                 };
86                 bo.insertBefore(div, bo.lastChild);
87         }
88 });
89 </script>
90 </body>
91 </html>

 

效果:

不惜勿喷?

转载于:https://www.cnblogs.com/brokencolor/p/10310670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值