Skip to content

Commit

Permalink
Refactored lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Plank committed Oct 9, 2011
1 parent d242ea2 commit e9a0eba
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 58 deletions.
58 changes: 0 additions & 58 deletions jquery.stickysectionheaders.js

This file was deleted.

60 changes: 60 additions & 0 deletions src/jquery.stickysectionheaders.js
@@ -0,0 +1,60 @@
/*!
* Sticky Section Headers
*
* Copyright (c) 2010 Florian Plank (http://www.polarblau.com/)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* USAGE:
*
* $('#container').stickySectionHeaders({
* stickyClass : 'sticky',
* headlineSelector : 'strong'
* });
*
*/

(function($){
$.fn.stickySectionHeaders = function(options) {

var settings = $.extend({
stickyClass : 'sticky',
headlineSelector: 'strong'
}, options);

return $(this).each(function() {
var $this = $(this);
$(this).find('ul:first').bind('scroll.sticky', function(e) {
$(this).find('> li').each(function() {
var $this = $(this),
top = $this.position().top,
height = $this.outerHeight(),
$head = $this.find(settings.headlineSelector),
headHeight = $head.outerHeight();

if (top < 0) {
$this.addClass(settings.stickyClass).css('paddingTop', headHeight);
$head.css('top', (height + top < headHeight) ? (headHeight - (top + height)) * -1 : '' );
} else {
$this.removeClass(settings.stickyClass).css('paddingTop', '');
}
});
});
});
};

/* A little helper to calculate the sum of different
* CSS properties
*
* EXAMPLE:
* $('#my-div').cssSum('paddingLeft', 'paddingRight');
*/
$.fn.cssSum = function() {
var $self = $(this), sum = 0;
$(arguments).each(function(i, e) {
sum += parseInt($self.css(e) || 0, 10);
});
return sum;
};

})(jQuery);

0 comments on commit e9a0eba

Please sign in to comment.