联级菜单的CSS与JS

Anchor : Drop Down Link

 
 


Single Select Form : Radio Input(Emulate Select/Option)

Legend
Select Option1
 
Select Option2
 



CSS Code

01 /* UI Object */
02 .select{ display:inline-block; *display:inlineposition:relativebackground:#fffline-height:normalvertical-align:middle; *zoom:1}
03 .select *{ margin:0padding:0font-size:12pxfont-family:TahomaSans-serifcursor:pointer}
04 .select .my_value{ overflow:visibleposition:relativetop:0left:0z-index:2border:1px solid #babababackground:transparentcolor:#666text-align:leftline-height:19px;_line-height:normal}
05 .select .my_value.selected{ font-weight:bold}
06 .select.open .my_value,
07 .select .my_value.outLine{ border:1px solid #999}
08 .select button.my_value{ width:100%height:21px; *padding-left:5pxtext-indent:5px; *text-indent:0}
09 .select div.my_value{ height:19pxtext-indent:8px}
10 .select .ctrl{ position:absolutetop:0right:0width:18pxheight:19pxborder:1px solid #babababorder-left:1px solid #eaeaeabackground:#fff}
11 .select .arrow{ position:absolutewidth:0height:0top:9pxright:6pxborder-top:3px solid #999border-left:3px solid #fffborder-right:3px solid #ffffont-size:0line-height:0}
12 .select ul{ overflow:hiddenposition:absolutetop:20pxleft:0width:100%border:0border-top:1px solid #babababorder-bottom:1px solid #babababackground:#ffflist-style:none}
13 .select ul.a_list{ display:none}
14 .select.open ul.a_list{ display:block}
15 .select ul.i_list{ left:-2000%}
16 .select.open ul.i_list{ left:0}
17 .select li{ overflow:hiddenposition:relativeheight:18pxborder-left:1px solid #babababorder-right:1px solid #bababawhite-space:nowrap}
18 .select li input.option{ position:absolutewidth:100%height:20pxline-height:20px}
19 .select li label{ position:absolutetop:0left:0width:100%height:18pxbackground:#fffcolor:#767676line-height:18pxtext-indent:8px; *text-indent:6px}
20 .select li a{ display:blockheight:18pxbackground:#fffcolor:#767676line-height:18pxtext-indent:8px; *text-indent:6pxtext-decoration:none}
21 .select li.hover *{ background:#999color:#fff}
22 .select_go{ overflow:visibleheight:21pxwidth:28px; *margin:-1px 0 -1px 4pxpadding:0border:1px solid #babababackground:#eeefont:bold 11px Tahomacolor:#767676line-height:19px_line-height:normalvertical-align:middlecursor:pointer}
23 /* //UI Object */

HTML Code

01 <!-- UI Object -->
02 <h1>Anchor :Drop Down Link</h1>
03 <div class="select" style="width:200px;">
04     <span class="ctrl"><span class="arrow"></span></span>
05     <button type="button" class="my_value">Select Link</button>
06     <ul class="a_list">
07     <li><a href="#1">Link_1</a></li>
08     <li><a href="#2">Link_2</a></li>
09     <li><a href="#3">Link_3</a></li>
10     </ul>
11 </div>
12 <div class="select" style="width:200px;">
13     <span class="ctrl"><span class="arrow"></span></span>
14     <button type="button" class="my_value">Select Link</button>
15     <ul class="a_list">
16     <li><a href="#1">Link_1</a></li>
17     <li><a href="#2">Link_2</a></li>
18     <li><a href="#3">Link_3</a></li>
19     </ul>
20 </div>
21 <br>
22 <br>
23 <br>
24 <h1>Single Select Form :Radio Input(Emulate Select/Option)</h1>
25 <form action="">
26     <fieldset>
27         <legend>Legend</legend>
28         <div class="select" style="width:200px;">
29             <span class="ctrl"><span class="arrow"></span></span>
30             <div class="my_value">Select Option1</div>
31             <ul class="i_list">
32             <li><input name="c" id="c0" type="radio" checked="checked" class="option"><label for="c0">Select Option1</label></li>
33             <li><input name="c" id="c1" type="radio" value="" class="option"><label for="c1">Option_1</label></li>
34             <li><input name="c" id="c2" type="radio" value="" class="option"><label for="c2">Option_2</label></li>
35             <li><input name="c" id="c3" type="radio" value="" class="option"><label for="c3">Option_3</label></li>
36             </ul>
37         </div>
38         <div class="select" style="width:200px;">
39             <span class="ctrl"><span class="arrow"></span></span>
40             <div class="my_value">Select Option2</div>
41             <ul class="i_list">
42             <li><input name="d" id="d0" type="radio" checked="checked" class="option"><label for="d0">Select Option2</label></li>
43             <li><input name="d" id="d1" type="radio" value="" class="option"><label for="d1">Option_1</label></li>
44             <li><input name="d" id="d2" type="radio" value="" class="option"><label for="d2">Option_2</label></li>
45             <li><input name="d" id="d3" type="radio" value="" class="option"><label for="d3">Option_3</label></li>
46             </ul>
47         </div>
48         <button type="submit" class="select_go">GO</button>
49     </fieldset>
50 </form>
51 <br>
52 <br>
53 <br>
54 <!-- //UI Object -->

JavaScript Code

01 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
02 <script type="text/javascript">
03 jQuery(function($){
04      
05     // Common
06     var select_root = $('div.select');
07     var select_value = $('.my_value');
08     var select_a = $('div.select>ul>li>a');
09     var select_input = $('div.select>ul>li>input[type=radio]');
10     var select_label = $('div.select>ul>li>label');
11      
12     // Radio Default Value
13     $('div.my_value').each(function(){
14         var default_value = $(this).next('.i_list').find('input[checked]').next('label').text();
15         $(this).append(default_value);
16     });
17      
18     // Line
19     select_value.bind('focusin',function(){$(this).addClass('outLine')});
20     select_value.bind('focusout',function(){$(this).removeClass('outLine')});
21     select_input.bind('focusin',function(){$(this).parents('div.select').children('div.my_value').addClass('outLine')});
22     select_input.bind('focusout',function(){$(this).parents('div.select').children('div.my_value').removeClass('outLine')});
23      
24     // Show
25     function show_option(){
26         $(this).parents('div.select:first').toggleClass('open');
27     }
28      
29     // Hover
30     function i_hover(){
31         $(this).parents('ul:first').children('li').removeClass('hover');
32         $(this).parents('li:first').toggleClass('hover');
33     }
34      
35     // Hide
36     function hide_option(){
37         var t = $(this);
38         setTimeout(function(){
39             t.parents('div.select:first').removeClass('open');
40         }, 1);
41     }
42      
43     // Set Input
44     function set_label(){
45         var v = $(this).next('label').text();
46         $(this).parents('ul:first').prev('.my_value').text('').append(v);
47         $(this).parents('ul:first').prev('.my_value').addClass('selected');
48     }
49      
50     // Set Anchor
51     function set_anchor(){
52         var v = $(this).text();
53         $(this).parents('ul:first').prev('.my_value').text('').append(v);
54         $(this).parents('ul:first').prev('.my_value').addClass('selected');
55     }
56  
57     // Anchor Focus Out
58     $('*:not("div.select a")').focus(function(){
59         $('.a_list').parent('.select').removeClass('open');
60     });
61              
62     select_value.click(show_option);
63     select_root.removeClass('open');
64     select_root.mouseleave(function(){$(this).removeClass('open')});
65     select_a.click(set_anchor).click(hide_option).focus(i_hover).hover(i_hover);
66     select_input.change(set_label).focus(set_label);
67     select_label.hover(i_hover).click(hide_option);
68      
69 });
70 </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值