Skip to content

Instantly share code, notes, and snippets.

@kyosuke
Created March 27, 2011 07:17
Show Gist options
  • Save kyosuke/889008 to your computer and use it in GitHub Desktop.
Save kyosuke/889008 to your computer and use it in GitHub Desktop.
jQuery.support.fixedPosition Original Code: http://kangax.github.com/cft/#IS_POSITION_FIXED_SUPPORTED
(function($){
$(function(){
$.support.fixedPosition = (function(){
var container = document.body;
if (document.createElement && container && container.appendChild && container.removeChild) {
var el = document.createElement('div');
if (!el.getBoundingClientRect) return null;
el.innerHTML = 'x';
el.style.cssText = 'position:fixed;top:100px;';
container.appendChild(el);
var originalHeight = container.style.height,
originalScrollTop = container.scrollTop;
container.style.height = '3000px';
container.scrollTop = 500;
var elementTop = el.getBoundingClientRect().top;
container.style.height = originalHeight;
var isSupported = (elementTop === 100);
container.removeChild(el);
container.scrollTop = originalScrollTop;
return isSupported;
}
return null;
}());
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment