1 /* 2 * stickyfloat - jQuery plugin for verticaly floating anything in a constrained area 3 * 4 * Example: jQuery('#menu').stickyfloat({duration: 400}); 5 * parameters: 6 * duration - the duration of the animation 7 * startOffset - the amount of scroll offset after it the animations kicks in 8 * offsetY - the offset from the top when the object is animated 9 * lockBottom - 'true' by default, set to false if you don't want your floating box to stop at parent's bottom 10 * $Version: 05.16.2009 r1 11 * Copyright (c) 2009 Yair Even-Or 12 * [email protected] 13 */ 14(function($) { 15 $.fn.stickyfloat = function(options, lockBottom) { 16 var $obj = this; 17 var parentPaddingTop = parseInt($obj.parent().css('padding-top')); 18 var startOffset = $obj.parent().offset().top; 19 var opts = $.extend({ startOffset: startOffset, offsetY: parentPaddingTop, duration: 200, lockBottom:true }, options); 20 $obj.css({ position: 'absolute' }); 21 22 //$obj.css({ 'margin-top': 95 }); 23 24 25 if(opts.lockBottom){ 26 var bottomPos = $obj.parent().height() - $obj.height() + parentPaddingTop; //get the maximum scrollTop value 27 if( bottomPos < 0 ) 28 bottomPos = 0; 29 } 30 31 $(window).scroll(function () { 32 33 $obj.stop(); // stop all calculations on scroll event 34 35 var pastStartOffset = $(document).scrollTop() > opts.startOffset; // check if the window was scrolled down more than the start offset declared. 36 var objFartherThanTopPos = $obj.offset().top > startOffset; // check if the object is at it's top position (starting point) 37 var objBiggerThanWindow = $obj.outerHeight() < $(window).height(); // if the window size is smaller than the Obj size, then do not animate. 38 39 40 // if window scrolled down more than startOffset OR obj position is greater than 41 // the top position possible (+ offsetY) AND window size must be bigger than Obj size 42 if( (pastStartOffset || objFartherThanTopPos) && objBiggerThanWindow ){ 43 44 var newpos = ($(document).scrollTop() -startOffset + opts.offsetY ); 45 46 if ( newpos > bottomPos ) 47 newpos = bottomPos; 48 49 if ( $(document).scrollTop() < opts.startOffset ) // if window scrolled < starting offset, then reset Obj position (opts.offsetY); 50 newpos = parentPaddingTop; 51 $obj.animate({ top: newpos }, opts.duration ); 52 53 54 } 55 }); 56 }; 57})(jQuery); 58 59jQuery(document).ready(function($){ 60 if( $('.menu-sidebar').length ) { 61 $('.menu-sidebar').stickyfloat({ duration: 0, stickToBottom: true/*, startOffset : 350*/ }); 62 } 63});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.