Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ipadStickyHeader = function() {
  2.                         var ipad = navigator.userAgent.match(/iPad/i);
  3.                         var landscapeOrientationCheck = window.matchMedia('(orientation: landscape)');
  4.                         var scrollPos;
  5.                         landscapeOrientationCheck.addListener(getOrientationValue);
  6.                         function getOrientationValue (mediaQuery) {
  7.                             // check if device is ipad in landscape mode
  8.                             if (ipad && mediaQuery.matches) {
  9.                                 if ($('input[type="text"]:not(".mh-sf-input")').is(':focus')) {
  10.                                     isSticky();
  11.                                 }
  12.                                 $( 'body' ).on( 'focus', 'input[type="text"]:not(".mh-sf-input")', isSticky);
  13.                                 $( 'body' ).on( 'blur', 'input[type="text"]:not(".mh-sf-input")', removeStickyClass);
  14.                                 w.on('touchmove', scrolling);
  15.                             }
  16.                             function scrolling() {
  17.                                 scrollPos = w.scrollTop();
  18.                                 if (scrollPos < mainHeaderHeight) {
  19.                                     removeStickyClass();
  20.                                 } else {
  21.                                     isSticky();
  22.                                 }
  23.                             }
  24.                             function removeStickyClass() {
  25.                                 $('.main-header').removeClass('sticky-main-header-fix');
  26.                                 $('.main-header').css({
  27.                                     top: 0,
  28.                                     position: 'relative'
  29.                                 });
  30.                             }
  31.                             function isSticky() {
  32.                                 $('.main-header').addClass('sticky-main-header-fix');
  33.                                 $('.sticky-main-header-fix').css({
  34.                                     top: mainHeaderHeight,
  35.                                     position: 'absolute'
  36.                                 });
  37.                             }
  38.                         }
  39.                     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement