Takazudo
10/1/2014 - 10:54 AM

position fixed detection

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