Created
May 22, 2010 04:02
-
-
Save bangpound/409753 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global jQuery */ | |
"use strict"; | |
/** | |
* jQuery balance plugin. | |
* | |
* Adds 1px padding to the right side of an element. If text wraps and | |
* causes the height of the element to increase, remove 1 pixel. | |
* | |
* $('h2.title').balance(); | |
*/ | |
(function ($) { | |
$.fn.balance = function () { | |
return this.each(function () { | |
var height, padding; | |
height = $(this).innerHeight(); | |
padding = 0; | |
if ($(this).text().match(/\s/)) { | |
$(this).height('auto'); | |
do { | |
padding += 1; | |
$(this).css({ paddingRight: padding }); | |
} | |
while ($(this).innerHeight() <= height); | |
padding -= 1; | |
$(this).css({ paddingRight: padding }); | |
} | |
}); | |
}; | |
})(jQuery); | |
/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, newcap: true, immed: true, indent: 2 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment