Why does someone need to hover over an event in the drop-down list? Here you can use the IE8 control method for how the dropdown should work:
First, make sure that we only pass our function to IE8:
var isIE8 = $.browser.version.substring(0, 2) === "8."; if (isIE8) {
Then, to allow the choice to expand beyond the content area, include our drop-down lists in a div with the correct structure, if not already, and then call the helper function:
var isIE8 = $.browser.version.substring(0, 2) === "8."; if (isIE8) { $('select').wrap('<div class="wrapper" style="position:relative; display: inline-block; float: left;"></div>').css('position', 'absolute');
Now for the events. Since IE8 throws an event after focusing for some reason, IE will close the widget after rendering when trying to expand. The work around will be binding to the 'focusin' and 'focusout' class, which will automatically expand based on the longest option text. Then, to ensure a constant minimum width that does not decrease after the default value, we can get the current width of the selection list and set it to the min-width property of the drop-down list in the 'onchange' binding:
function ddlFix() { var minWidth; $('select') .each(function () { minWidth = $(this).width(); $(this).css('min-width', minWidth); }) .bind('focusin', function () { $(this).addClass('expand'); }) .change(function () { $(this).css('width', minWidth); }) .bind('focusout', function () { $(this).removeClass('expand'); }); }
Finally, remember to add this class to the stylesheet:
select:focus, select.expand { width: auto; }
Ben Sewards Sep 20 '12 at 20:00 2012-09-20 20:00
source share