Created
April 13, 2011 20:49
-
-
Save irae/918381 to your computer and use it in GitHub Desktop.
Select with Pointer Events jQuery and Modernizr
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
Modernizr.addTest('pointerevents',function(){ | |
var div = document.createElement('div'); | |
if ('pointerEvents' in div.style) return true; | |
'Webkit Moz O ms Khtml'.replace(/([A-Za-z]*)/g,function(val){ | |
if (val+'PointerEvents' in div.style) return true; | |
}); | |
}); |
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
/* Css uses Sass */ | |
.borderimage select, | |
.pointerevents .selectWrapper .selectPointerOver { | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
border-width: 4px 25px 4px 4px; | |
-moz-border-image: url('/images/assets/bg-select-borde-image.png') 4 25 4 4 stretch; | |
-webkit-border-image: url('/images/assets/bg-select-borde-image.png') 4 25 4 4 stretch; | |
-o-border-image: url('/images/assets/bg-select-borde-image.png') 4 25 4 4 stretch; | |
border-image: url('/images/assets/bg-select-borde-image.png') 4 25 4 4 stretch; | |
-moz-border-radius: 6px; | |
-webkit-border-radius: 6px; | |
border-radius: 6px; | |
height:28px; | |
} | |
.pointerevents .selectWrapper { | |
display:inline-block;margin:0;padding:0;background:transparent;position:relative; | |
.selectPointerOver { | |
pointer-events:none;display:block;position:absolute;top:0;left:0;padding:2px 4px;margin:0; | |
} | |
} | |
.no-borderimage select { | |
-webkit-box-sizing: border-box; | |
-moz-box-sizing: border-box; | |
box-sizing: border-box; | |
height:28px; | |
} |
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
if(Modernizr.pointerevents && Modernizr.borderimage) { | |
$('#main').delegate('select', 'change', function() { | |
$(this).nextAll('.selectPointerOver').html($(this).val()); | |
}); | |
$('select') | |
.wrap('<span class="selectWrapper"/>') | |
.each(function(){ | |
var that = $(this); | |
$('<span class="selectPointerOver">'+that.val()+'</span>') | |
.css('width',(parseInt(that.width(),10)+29)+'px') | |
.insertAfter(this) | |
; | |
}) | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment