Anchor : Drop Down Link
Single Select Form : Radio Input(Emulate Select/Option)
CSS Code
01 | /* UI Object */ |
02 | .select{ display:inline-block; *display:inline; position:relative; background:#fff; line-height:normal; vertical-align:middle; *zoom:1} |
03 | .select *{ margin:0; padding:0; font-size:12px; font-family:Tahoma, Sans-serif; cursor:pointer} |
04 | .select .my_value{ overflow:visible; position:relative; top:0; left:0; z-index:2; border:1px solid #bababa; background:transparent; color:#666; text-align:left; line-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:5px; text-indent:5px; *text-indent:0} |
09 | .select div.my_value{ height:19px; text-indent:8px} |
10 | .select .ctrl{ position:absolute; top:0; right:0; width:18px; height:19px; border:1px solid #bababa; border-left:1px solid #eaeaea; background:#fff} |
11 | .select .arrow{ position:absolute; width:0; height:0; top:9px; right:6px; border-top:3px solid #999; border-left:3px solid #fff; border-right:3px solid #fff; font-size:0; line-height:0} |
12 | .select ul{ overflow:hidden; position:absolute; top:20px; left:0; width:100%; border:0; border-top:1px solid #bababa; border-bottom:1px solid #bababa; background:#fff; list-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:hidden; position:relative; height:18px; border-left:1px solid #bababa; border-right:1px solid #bababa; white-space:nowrap} |
18 | .select li input.option{ position:absolute; width:100%; height:20px; line-height:20px} |
19 | .select li label{ position:absolute; top:0; left:0; width:100%; height:18px; background:#fff; color:#767676; line-height:18px; text-indent:8px; *text-indent:6px} |
20 | .select li a{ display:block; height:18px; background:#fff; color:#767676; line-height:18px; text-indent:8px; *text-indent:6px; text-decoration:none} |
21 | .select li.hover *{ background:#999; color:#fff} |
22 | .select_go{ overflow:visible; height:21px; width:28px; *margin:-1px 0 -1px 4px; padding:0; border:1px solid #bababa; background:#eee; font:bold 11px Tahoma; color:#767676; line-height:19px; _line-height:normal; vertical-align:middle; cursor: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> |


5778

被折叠的 条评论
为什么被折叠?



