# DropDown
Open me!
Demo View | Source Code (opens new window) | Download all widgets
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../core/lib/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="dropdown.js"></script>
<link type="text/css" rel="stylesheet" href="style.css">
<title>Custom dropdown</title>
</head>
<body>
<h1>Custom dropdown</h1>
<div>
<select class="styled">
<option>Item 1</option>
<option>Item 2</option>
<option>Item 3</option>
<option>Item 4</option>
<option>Item 5</option>
<option>Item 6</option>
<option>Item 7</option>
<option>Item 8</option>
<option>Item 9</option>
<option>Item 10</option>
</select>
</div>
</body>
</html>
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
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
.styled {
width: 150px;
}
span.customStyleSelectBox {
margin-top: 7px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
background-color: #ffffff;
color: #000000;
padding: 5px 7px;
border: 1px solid #efefef;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px 5px;
line-height: 11px;
}
span.customStyleSelectBox.changed {
background-color: #efefef;
}
.customStyleSelectBoxInner {
background:url("../core/images/dropdown_arrow.gif") no-repeat center right;
}
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(function ($) {
$('select.styled').customStyle();
$.fn.extend({
customStyle: function (options) {
if (!$.browser.msie || ($.browser.msie && $.browser.version > 6)) {
return this.each(function () {
var currentSelected = $(this).find(':selected');
$(this).after('<span class="customStyleSelectBox"><span class="customStyleSelectBoxInner">' + currentSelected.text() + '</span></span>').css({ position: 'absolute', opacity: 0, fontSize: $(this).next().css('font-size') });
var selectBoxSpan = $(this).next();
var selectBoxWidth = parseInt($(this).width()) - parseInt(selectBoxSpan.css('padding-left')) - parseInt(selectBoxSpan.css('padding-right'));
var selectBoxSpanInner = selectBoxSpan.find(':first-child');
selectBoxSpan.css({ display: 'inline-block' });
selectBoxSpanInner.css({ width: selectBoxWidth, display: 'inline-block' });
var selectBoxHeight = parseInt(selectBoxSpan.height()) + parseInt(selectBoxSpan.css('padding-top')) + parseInt(selectBoxSpan.css('padding-bottom'));
$(this).height(selectBoxHeight).change(function () {
selectBoxSpanInner.text($(this).find(':selected').text()).parent().addClass('span.customStyleSelectBox.changed');
});
});
}
}
});
})(jQuery);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Make sure to add code blocks to your code group