Created
December 13, 2011 07:02
-
-
Save scottjehl/1470996 to your computer and use it in GitHub Desktop.
jQuery-based Position Fixed Feature Test
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
/* jQuery-based feature test for CSS position: fixed support. | |
Modified from Kangax's test (http://kangax.github.com/cft/#IS_POSITION_FIXED_SUPPORTED) in two ways: 1) uses jQuery API, 2) remove document.body dependency. | |
Method changes aside, the required workaround for dropping document.body use was to set scroll using window.scrollTo instead of body.scrollTop. | |
//Testing notes: | |
iOS4.3: false (expected) | |
iOS5: true (expected) | |
Chrome latest: true (expected) | |
...more soon | |
*/ | |
$.support.positionFixed = (function (){ | |
var contain = $( document.documentElement ), | |
el = $( "<div style='position:fixed;top:100px;'>x</div>" ).appendTo( contain ), | |
originalHeight = contain[ 0 ].style.height, | |
w = window, | |
result; | |
contain.height( screen.height * 2 + "px" ); | |
w.scrollTo( 0, 100 ); | |
result = el[ 0 ].getBoundingClientRect().top === 100; | |
contain.height( originalHeight ); | |
el.remove(); | |
w.scrollTo( 0, 0 ); | |
return result; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment