Created
November 17, 2011 13:33
-
-
Save zrod/1373141 to your computer and use it in GitHub Desktop.
Fixed width for IE Select elements (< 9)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
if ($.browser.msie && $.browser.version.charAt(0) < 9) myScript.ieSelectFixedWidth('select.mini, select.medium'); | |
} | |
// ... | |
var myScript = { | |
ieSelectFixedWidth: function(el) { | |
$(el).each(function(k, v) { | |
var obj = $(v); | |
if (obj.length > 0) { | |
var objWidth = obj.outerWidth(), | |
objContainerId = obj.attr('id') + '_options', | |
objContainer = $('<span id="' + objContainerId + '" class="ieSelectFixedWidthContainer" />').css('width', objWidth), | |
widthSet = false; | |
obj.wrap(objContainer); | |
obj.bind("click mousedown focusin", function () { | |
displaySelectOverlay(); | |
}); | |
obj.bind("blur change focusout", function() { | |
hideSelectOverlay(); | |
}); | |
function displaySelectOverlay() { | |
if (!widthSet) { | |
obj.css({'position': 'relative', 'width': 'auto'}); | |
if (obj.outerWidth() < obj.parent().innerWidth()) { | |
obj.css('width', objWidth); | |
widthSet = true; | |
} | |
} | |
} | |
function hideSelectOverlay() { | |
obj.css('width', objWidth); | |
} | |
} | |
}); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ieSelectFixedWidthContainer { | |
position: relative; | |
overflow: hidden; | |
display: inline-block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment