Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created April 10, 2010 17:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulirish/362170 to your computer and use it in GitHub Desktop.
Save paulirish/362170 to your computer and use it in GitHub Desktop.
// jQuery.support.(displayTable|displayTableCell|margin0auto|positionFixed)
// jQuery.support.displayTable and displayTableCell -
// to determine browser support for setting elements to that css display value
$.each(['','-cell'],function(k,v){
$.support['displayTable'+v.replace('-c','C')] = (function(){
var elem = $('<div>',{
css : {
display: 'table'+v,
position: 'absolute',
visibility: 'hidden'
}
}).appendTo(document.body || document.documentElement),
support = ('table'+v) === elem.css('display');
elem.remove();
return support;
})();
})
// jQuery.support.margin0auto
// to verify that '0 auto' will center things. (ie6 should fail..)
$.support.margin0auto = (function(){
var elem = $('<div style="width: 10px; position: relative; "><div style="margin-top: 0px; margin-right: auto; margin-bottom: 0px; margin-left: auto; width: 2px; "></div></div>')
.appendTo(document.body || document.documentElement),
support = elem.children()[0].offsetLeft === 4;
elem.remove();
return support;
})();
// jQuery.support.positionFixed
// does the browser support `position:fixed`
$.support.positionFixed = (function(){
var elem = $('<div>',{
css : {
position: 'fixed',
top: '42px',
visibility: 'hidden'
}
}).appendTo(document.body || document.documentElement),
// also account for page scroll
support = parseInt(elem.offset().top,10) - (document.body ? document.body.scrollTop : 0) === 42;
elem.remove();
return support;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment