Skip to content

Instantly share code, notes, and snippets.

@zoxon
Forked from Takazudo/detectPositionFixed.js
Created February 17, 2018 13:58
Show Gist options
  • Save zoxon/e104e01930b8800ecf36899ff05c23e5 to your computer and use it in GitHub Desktop.
Save zoxon/e104e01930b8800ecf36899ff05c23e5 to your computer and use it in GitHub Desktop.
position fixed detection
// a little modified version of
// position: fixed support detection from jQuery mobile.
//
// This script also defines Android2.x as out of support.
//
// https://github.com/jquery/jquery-mobile/blob/master/js/support.js
// http://demos.jquerymobile.com/1.4.4/toolbar-fixed/
// http://jimbergman.net/webkit-version-in-android-version/
Modernizr.addTest('positionfixed', function() {
var w = window,
ua = navigator.userAgent,
platform = navigator.platform,
// Rendering engine is Webkit, and capture major version
wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ ),
wkversion = !!wkmatch && wkmatch[ 1 ],
ffmatch = ua.match( /Fennec\/([0-9]+)/ ),
ffversion = !!ffmatch && ffmatch[ 1 ],
operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ ),
omversion = !!operammobilematch && operammobilematch[ 1 ];
if (
// iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
( ( platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534 ) ||
// Opera Mini
( w.operamini && ({}).toString.call( w.operamini ) === "[object OperaMini]" ) ||
( operammobilematch && omversion < 7458 ) ||
//Android lt 3: Platform is Android and Webkit version is less than 534 (Android 3.2.1)
( ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 534 ) ||
// Firefox Mobile before 6.0 -
( ffversion && ffversion < 6 ) ||
// WebOS less than 3
( "palmGetResource" in window && wkversion && wkversion < 534 ) ||
// MeeGo
( ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1 ) ) {
return false;
}
return true;
});
console.log(Modernizr.positionfixed); // true or false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment