Skip to content

Instantly share code, notes, and snippets.

@vyspiansky
Forked from scottjehl/support-posfixed.js
Created March 27, 2014 21:11
Show Gist options
  • Save vyspiansky/9818968 to your computer and use it in GitHub Desktop.
Save vyspiansky/9818968 to your computer and use it in GitHub Desktop.
jQuery: test for CSS position: fixed support
/* 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