Created
March 27, 2011 07:17
-
-
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
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
(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