1.1.0 ā€¢ Published 2 years ago

multiple-equalizer v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Multiple Equalizer šŸ“

It is made to equalize elements when necessary. For example the most used case is in cards, so that when one has more content the other adjusts to its size even if it has less content.

Instalation: šŸ”§

npm i multiple-equalizer

Usage:

Import function:

import { multipleEqualizer } from  "multiple-equalizer"; 

Call function on window load and resize:

window.addEventListener('DOMContentLoaded', () => {
    // Run equalizer when fonts are loaded
    if (typeof document.fonts == 'undefined') {
        multipleEqualizer();
    } else {
        document.fonts.ready.then(function () {
            multipleEqualizer();
        })
    }
})

window.addEventListener('resize', () => {
    multipleEqualizer();
})

Props: šŸ’»

Property NameDescriptionDefault Value
data-alloyEqualize-multipleMain property of the plugin, this needs to be set on the parent/wrapper component of the elements that are going to be equalized. Its value is a number from 1 to N depending on how many elements of its children needs to be equalized.-
data-alloyequalize-watch-NAll the children elements that are going to be equalized needs to have this prop replacing the N with an integer number.-

šŸ“ Example:

<div data-alloyEqualize-multiple="3">
	<div class="amazing-card">
		<div data-alloyequalize-watch-1>Your amazing card equalizable title here</div>
		<div data-alloyequalize-watch-2>Your amazing card equalizable summary here</div>
		<div data-alloyequalize-watch-3>Your amazing card equalizable author name here</div>
	</div>
	<div class="amazing-card">
		<div data-alloyequalize-watch-1>Your amazing card equalizable title here</div>
		<div data-alloyequalize-watch-2>Your amazing card equalizable summary here</div>
		<div data-alloyequalize-watch-3>Your amazing card equalizable author name here</div>
	</div>
	<div class="amazing-card">
		<div data-alloyequalize-watch-1>Your amazing card equalizable title here</div>
		<div data-alloyequalize-watch-2>Your amazing card equalizable summary here</div>
		<div data-alloyequalize-watch-3>Your amazing card equalizable author name here</div>
	</div>
</div>

šŸ„½ The end result would be something like this:

multiple equalizer cards example

How it works: āš™āš™āš™

  • Each element inside the parent data-alloyEqualize-multiple will have the same height as the tallest element

  • Sibling items attr^="data-alloyequalize-watch-" are compared as long as they belong to the same parent element, regardless of whether the front-end visually displays a row