Skip to content

cryocreations/equalizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

equalizer.js

A lightweight jQuery plugin to equalize element heights.

Features

  • Equalize the heights of any element
  • Responsive control with breakpoint handling
  • Handles padding, border properties
  • Use HTML data attributes to initialize and customize Equalizer without using javascript
  • Callback events
  • Minimum and maximum height limiting
  • Toggle class names for inactive and active equalized elements
  • Increased performance
  • Tested in IE, Chrome, Firefox, Safari
  • Only 2kb

Requirements

This plugin requires jQuery 1.7+

Getting Started

Installing

Add the script after the jQuery library. Adding this code before the end of the <body> tag is preferred.

<scriptsrc="equalizer.min.js"></script>

Basic Usage

There are two ways that Equalizer can be used: the HTML data attribute or using jQuery. In HTML, only child elements within the target will be equalized and will not exceed the scope. It is recommended to use the HTML attribute unless you need event callbacks.

Using HTML data attributes

<divclass="row" data-eq><divclass="column" data-eq-band><br><p>Bacon ipsum dolor amet ham alcatra jowl beef pastrami chuck kevin capicola. Bacon ribeye pork belly pancetta short loin flank.</p></div><divclass="column" data-eq-band><br><p>Swine capicola porchetta, salami tri-tip pork loin pork t-bone hamburger jowl chuck landjaeger ribeye flank. Prosciutto boudin cupim, shankle tail rump salami shoulder.</p></div><divclass="column" data-eq-band><br><p>Ribeye ham alcatra jowl kielbasa chicken doner short loin biltong tenderloin.</p></div><divclass="column" data-eq-band><br><p>Short loin kielbasa rump, pork belly boudin kevin drumstick jerky meatloaf frankfurter leberkas pancetta corned beef hamburger burgdoggen. Cow pancetta beef, corned beef prosciutto chicken tail shoulder filet mignon.</p></div></div>

Using jQuery

<divclass="row" id="example"><divclass="column"><br><p>Bacon ipsum dolor amet ham alcatra jowl beef pastrami chuck kevin capicola. Bacon ribeye pork belly pancetta short loin flank.</p></div><divclass="column"><br><p>Swine capicola porchetta, salami tri-tip pork loin pork t-bone hamburger jowl chuck landjaeger ribeye flank. Prosciutto boudin cupim, shankle tail rump salami shoulder.</p></div><divclass="column"><br><p>Ribeye ham alcatra jowl kielbasa chicken doner short loin biltong tenderloin.</p></div><divclass="column"><br><p>Short loin kielbasa rump, pork belly boudin kevin drumstick jerky meatloaf frankfurter leberkas pancetta corned beef hamburger burgdoggen. Cow pancetta beef, corned beef prosciutto chicken tail shoulder filet mignon.</p></div></div>
$(document).ready(function(){$('#example .column').equalizer();});

Options

Below are the available settings and the default value that gets passed to the equalizer() function. You can also modify defaults directly in the equalizer.js file.

SettingTypeDefaultDescription
unequalizeNumber0When the window viewport is lower than this value (in pixels), Equalizer will disable equalizing methods and revert the targets to their natural height.
minimumNumbernullSets the minimum height to each target.
maximumNumbernullStop the target's height from exceeding this value.
overflowScrollBooleanfalseThis value will enable/disable scrolling of the target if the inner content is larger then element height. Note: this setting only works in conjuction with the "maximum" option.
unequalizedClassStringunequalizedThis CSS class will be added to each target that is not equalized. Note: this setting only works in conjuction with the "unequalize" option.
equalizedClassStringequalizedThis CSS class will be added to each target that is equalized.

Options Examples

Using HTML data attributes

<divclass="row" data-eq=".column" data-eq-settings='{"unequalize":0, "minimum":null, "maximum":null, "overflowScroll":false, "equalizedClass":"equalized", "unequalizedClass":"unequalized"}'><divclass="column"><br><p>Bacon ipsum dolor amet ham alcatra jowl beef pastrami chuck kevin capicola. Bacon ribeye pork belly pancetta short loin flank.</p></div><divclass="column"><br><p>Swine capicola porchetta, salami tri-tip pork loin pork t-bone hamburger jowl chuck landjaeger ribeye flank. Prosciutto boudin cupim, shankle tail rump salami shoulder.</p></div><divclass="column"><br><p>Ribeye ham alcatra jowl kielbasa chicken doner short loin biltong tenderloin.</p></div><divclass="column"><br><p>Short loin kielbasa rump, pork belly boudin kevin drumstick jerky meatloaf frankfurter leberkas pancetta corned beef hamburger burgdoggen. Cow pancetta beef, corned beef prosciutto chicken tail shoulder filet mignon.</p></div></div>

Note: you cannot use callbacks in the HTML data attributes.

Using jQuery

<divclass="row" id="example"><divclass="column"><br><p>Bacon ipsum dolor amet ham alcatra jowl beef pastrami chuck kevin capicola. Bacon ribeye pork belly pancetta short loin flank.</p></div><divclass="column"><br><p>Swine capicola porchetta, salami tri-tip pork loin pork t-bone hamburger jowl chuck landjaeger ribeye flank. Prosciutto boudin cupim, shankle tail rump salami shoulder.</p></div><divclass="column"><br><p>Ribeye ham alcatra jowl kielbasa chicken doner short loin biltong tenderloin.</p></div><divclass="column"><br><p>Short loin kielbasa rump, pork belly boudin kevin drumstick jerky meatloaf frankfurter leberkas pancetta corned beef hamburger burgdoggen. Cow pancetta beef, corned beef prosciutto chicken tail shoulder filet mignon.</p></div></div>
$(document).ready(function(){$('#example .column').equalizer({unequalize:0,minimum:null,maximum:null,overflowScroll:false,equalizedClass:'equalized',unequalizedClass:'unequalized'});});

Callbacks

Below are the available settings and their default values that get passed to the equalizer() function. You can also modify defaults directly in the equalizer.js file.

SettingTypeDefaultReturnsDescription
onEqualizeFunctionnullObjectThis function will fire every time the targets have increased or decreased height. This occurs when the viewport width or device orientation changes.
onUnequalizeFunctionnullObjectThis function will fire when the the unequilize value has been met. Note: this is dependent on the "unequalize" setting.

Callback Examples

<divclass="row" id="example"><divclass="column"><br><p>Bacon ipsum dolor amet ham alcatra jowl beef pastrami chuck kevin capicola. Bacon ribeye pork belly pancetta short loin flank.</p></div><divclass="column"><br><p>Swine capicola porchetta, salami tri-tip pork loin pork t-bone hamburger jowl chuck landjaeger ribeye flank. Prosciutto boudin cupim, shankle tail rump salami shoulder.</p></div><divclass="column"><br><p>Ribeye ham alcatra jowl kielbasa chicken doner short loin biltong tenderloin.</p></div><divclass="column"><br><p>Short loin kielbasa rump, pork belly boudin kevin drumstick jerky meatloaf frankfurter leberkas pancetta corned beef hamburger burgdoggen. Cow pancetta beef, corned beef prosciutto chicken tail shoulder filet mignon.</p></div></div>
$(document).ready(function(){$('#example .column').equalizer({onEqualize:function(){console.log('Equalized!');},onUnequalize:function(){console.log('Unequalized!');}});});

Change Log

  • Version 1.0
    • Launched plugin

For the versions available, see the tags on this repository.

Author

Matt Frazee | GitHub | Twitter | Stack Overflow

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A lightweight jQuery plugin to equalize element heights.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published