I'm trying to build my own custom dropdown menu that should remember it's vertical position like a normal <select> tag. The dropdown works fine already there is just this little thingy I want to improve.
this is my html structure:
<div class="select width210" id="sortby1">
<ul>
<li class="option darr" title="all">show all</li>
<li class="option" title="published">published only</li>
<li class="option" title="unpublished">private only</li>
</ul>
</div>
this is my jquery:
/**
* Select Boxes
*
*/
var currentSelectDiv = null;
$('.select ul li.option').click(function(e) {
//storing the id attribute
currentSelectDiv = $(this).parents("div.select").attr("id");
$(this).siblings().toggle().removeClass('darr');
$(this).addClass('darr');
});
$(document).click(function(e) {
$('.select ul li.option').each(function() {
// check IDs to make sure only closing other lis
if( $(this).parents("div.select").attr("id") !=
currentSelectDiv) {
if ( !$(this).is(":hidden" ) ) {
$(this).not('.darr').toggle();
}
}
});
currentSelectDiv = null;
});
The problem is I can't actually explain the thing without referencing to a live example. http://jsfiddle.net/veUwn/
As you can see the dropdown works like a charm. It behaves like an actual drop down where the li.option's are actually dropping DOWN. However I don't want them to dropdown but remain its vertical position just like the actual select field underneath. If you select a option further down in the select field the vertical position of the select stays intact - so the options are not actually dropping down but just appear in a layer above.
Any idea how I can achieve the same thingy with my own select.ul's ?
Thank you for your help.
edit:

selecttag does in webkit browsers. E.g. open my jsfiddle sample with chrome or safari and click the<select>, choose a option at the bottom of the select tag and close the input - then open it again und you see that the options of the select tag "stand out". So they're not actually dropping down anymore but the current selected element keeps its position. In my case its a regular dropdown. I want it to behave like the select field and keep its position.