title: How do I prevent a script from running on mobile devices?
body: <p>My website features a sticky navigation, but it won't work on mobile devices...</p>
  
  <p>How do I <strong>make it sticky</strong> on mobile devices, or how do I <strong>prevent it from being sticky</strong> (while keeping the navigation, of course)?</p>
  
  <p>I looked everywhere for an answer, but couldn't find one that worked (and didn't disable my navigation:) Your help is much appreciated!</p>
  
  <p>This is a part of my index.html header:</p>
  
  <pre><code>&lt;head&gt;
  
  &lt;link href="css/reset.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="css/960.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="css/styles.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="fancybox/jquery.fancybox-1.3.4.css" rel="stylesheet" type="text/css" /&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="js/smooth-scroll.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.sticky.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="contactform.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;!-- sticky nav --&gt;
  &lt;script type="text/javascript"&gt;
  $(window).load(function(){
  $("nav").sticky({ topSpacing: 0, className: 'sticky', center: true });
  });
  &lt;/script&gt;
  
  &lt;/head&gt;
  </code></pre>
  
  <p>And this is the code in the jquery.sticky javascript:</p>
  
  <pre><code>(function($) {
  var defaults = {
          topSpacing: 0,
          bottomSpacing: 0,
          className: 'is-sticky',
          center: false
      },
      $window = $(window),
      $document = $(document),
      sticked = [],
      windowHeight = $window.height(),
      scroller = function() {
          var scrollTop = $window.scrollTop(),
              documentHeight = $document.height(),
              dwh = documentHeight - windowHeight,
              extra = (scrollTop &gt; dwh) ? dwh - scrollTop : 0;
          for (var i = 0; i &lt; sticked.length; i++) {
              var s = sticked[i],
                  elementTop = s.stickyWrapper.offset().top,
                  etse = elementTop - s.topSpacing - extra;
              if (scrollTop &lt;= etse) {
                  if (s.currentTop !== null) {
                      s.stickyElement.css('position', '').css('top', '').removeClass(s.className);
                      s.currentTop = null;
                  }
              }
              else {
                  var newTop = documentHeight - s.elementHeight - s.topSpacing - s.bottomSpacing - scrollTop - extra;
                  if (newTop &lt; 0) {
                      newTop = newTop + s.topSpacing;
                  } else {
                      newTop = s.topSpacing;
                  }
                  if (s.currentTop != newTop) {
                      s.stickyElement.css('position', 'fixed').css('top', newTop).addClass(s.className);
                      s.currentTop = newTop;
                  }
              }
          }
      },
      resizer = function() {
          windowHeight = $window.height();
      };
  
  // should be more efficient than using $window.scroll(scroller) and $window.resize(resizer):
  if (window.addEventListener) {
      window.addEventListener('scroll', scroller, false);
      window.addEventListener('resize', resizer, false);
  } else if (window.attachEvent) {
      window.attachEvent('onscroll', scroller);
      window.attachEvent('onresize', resizer);
  }
  
  $.fn.sticky = function(options) {
      var o = $.extend(defaults, options);
      return this.each(function() {
          var stickyElement = $(this);
          if (o.center)
              var centerElement = "margin-left:auto;margin-right:auto;";
  
          stickyId = stickyElement.attr('id');
          stickyElement
              .wrapAll('&lt;div id="' + stickyId + 'StickyWrapper" style="' + centerElement + '"&gt;&lt;/div&gt;')
              .css('width', stickyElement.width());
          var elementHeight = stickyElement.outerHeight(),
              stickyWrapper = stickyElement.parent();
          stickyWrapper
              .css('width', stickyElement.outerWidth())
              .css('height', elementHeight)
              .css('clear', stickyElement.css('clear'));
          sticked.push({
              topSpacing: o.topSpacing,
              bottomSpacing: o.bottomSpacing,
              stickyElement: stickyElement,
              currentTop: null,
              stickyWrapper: stickyWrapper,
              elementHeight: elementHeight,
              className: o.className
          });
      });
  };
  })(jQuery);
  </code></pre>