/
jquery.ba-equalizebottoms.js
90 lines (81 loc) · 2.9 KB
/
jquery.ba-equalizebottoms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*!
* jQuery equalizeBottoms - v1.5 - 3/23/2010
* http://benalman.com/projects/jquery-equalizebottoms-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// Script: jQuery equalizeBottoms
//
// *Version: 1.5, Date: 3/23/2010*
//
// Project Home - http://benalman.com/projects/jquery-equalizebottoms-plugin/
// GitHub - http://github.com/cowboy/jquery-equalizebottoms/
// Source - http://github.com/cowboy/jquery-equalizebottoms/raw/master/jquery.ba-equalizebottoms.js
// (Minified) - http://github.com/cowboy/jquery-equalizebottoms/raw/master/jquery.ba-equalizebottoms.min.js (0.5kb)
//
// About: License
//
// Copyright (c) 2010 "Cowboy" Ben Alman,
// Dual licensed under the MIT and GPL licenses.
// http://benalman.com/about/license/
//
// About: Examples
//
// This working example, complete with fully commented code, illustrates a few
// ways in which this plugin can be used.
//
// Equalize Bottoms - http://benalman.com/code/projects/jquery-equalizebottoms/examples/equalizebottoms/
//
// About: Support and Testing
//
// Information about what version or versions of jQuery this plugin has been
// tested with and what browsers it has been tested in.
//
// jQuery Versions - 1.3.2, 1.4.2
// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
//
// About: Release History
//
// 1.5 - (3/23/2010) Changed .height measurement to .outerHeight to take
// padding and border into consideration.
// 1.4 - (11/7/2009) Removed polling functionality. If you need polling, use
// in combination with jQuery doTimeout.
// 1.3 - (4/4/2009) Initial release
(function($) {
'$:nomunge'; // Used by YUI compressor.
// Method: jQuery.fn.equalizeBottoms
//
// Equalize the bottoms of all selected elements.
//
// Usage:
//
// > jQuery('selector').equalizeBottoms( [ bottom ] );
//
// Arguments:
//
// bottom - (Number) An optional bottom y position to force selected element
// bottoms to. If omitted, bottom is computed automatically by measuring
// height of all selected elements and choosing the bottom-most bottom. You
// will probably never, ever use this.
//
// Returns:
//
// (jQuery) The initial jQuery collection of elements.
$.fn.equalizeBottoms = function( bottom ) {
if ( isNaN( bottom ) ) {
bottom = 0;
// Reset height first, then get the bottom-most bottom.
this.each(function(){
var that = $(this).css({ height: 'auto' });
bottom = Math.max( bottom, that.offset().top + that.outerHeight() );
});
}
// Update all bottoms, taking padding and border height into consideration.
return this.each(function(){
var that = $(this);
that.height( bottom - that.offset().top - that.outerHeight() + that.height() );
});
};
})(jQuery);