0.33.0 • Published 9 years ago

jquery-sizes v0.33.0

Weekly downloads
97
License
-
Repository
github
Last release
9 years ago

JSizes ― jQuery extension plugin for CSS properties

JSizes is a small plugin for the jQuery JavaScript library which adds convenience methods for querying and setting the CSS min-width, min-height, max-width, max-height, border-*-width, margin, and padding properties. Additionally it has one method for determining whether an element is visible. In total it adds six new methods to the jQuery element API. It internally calls the jQuery built-in css method, so syntax and use is identical to calling css('property-name', ...). An example of its use follows.

jQuery(function($) {
   var myDiv = $('#myDiv');

   myDiv.minWidth(100); // set 'min-width' to 100px
   alert(myDiv.minWidth()); // displays '100'
});

Note that all returned values are converted to pixel values, without the px suffix. It is thus safe to use these methods in calculations without having to worry about non-numeric values. Most importantly, it does not add support for min- and max-sizes on browsers that do not natively support it, it just adds convenient methods to query these properties and return a sensible value when they are not available or not set.

API

The plugin adds the following methods to the JQuery object:

Examples

Some examples of how the new methods can be used:

jQuery(function($) {
   var myDiv = $('#myDiv');

   // set margin-top to 100px and margin-bottom to 10em
   myDiv.margin({top: 100, bottom: '10em'});

   // displays the size of the top border in pixels
   alert(myDiv.border().top);

   // displays true if the element is visible, false otherwise
   alert(myDiv.isVisible());

   // set padding-right to 10px and margin-left to 15px using chaining
   myDiv.padding({right: 10}).margin({left: 15});
});

The above example also shows that chaining can be used on methods that do not return values.

Credits

  • John Bowers ― Setting values to zero bug fix.