Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/azoku (11-Feb @ 19:15)

Syntax Highlighted Code

  1. $.fn.fuckingAwesome = function( options ) {
  2.     var self = this,
  3.         win = $( window );
  4.     options = $.extend( { min: 0 }, options );
  5.     if ( options.min === "auto" ) { options.min = self.offset().top; }
  6.     win.bind( "scroll resize", function() {
  7.         var windowTop = win.scrollTop(),
  8.             currentTop = self.offset().top;
  9.        
  10.         if ( windowTop > options.min || currentTop > options.min ) {
  11.             var top = Math.max( windowTop, options.min );
  12.             if ( options.max ) {
  13.                 top = Math.min( top, $.isFunction(options.max) ? options.max() : options.max );
  14.             }
  15.             self.stop().animate({
  16.                 top: top
  17.             }, 200);
  18.         }
  19.     });
  20. };

Plain Code

$.fn.fuckingAwesome = function( options ) {
    var self = this,
        win = $( window );
    options = $.extend( { min: 0 }, options );
    if ( options.min === "auto" ) { options.min = self.offset().top; }
    win.bind( "scroll resize", function() {
        var windowTop = win.scrollTop(),
            currentTop = self.offset().top;
        
        if ( windowTop > options.min || currentTop > options.min ) {
            var top = Math.max( windowTop, options.min );
            if ( options.max ) {
                top = Math.min( top, $.isFunction(options.max) ? options.max() : options.max );
            }
            self.stop().animate({
                top: top
            }, 200);
        }
    });
};

Permalink: http://codedumper.com/azoku