Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@teamteanpm2024/vel-harum-ab
Advanced tools
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) [![Socket Badge](https://socket.dev
matchHeight: makes the height of all selected elements exactly equal
Demo - Features - Install - Usage - Options - Data API
Advanced Usage - Changelog - License
See the @teamteanpm2024/vel-harum-ab.js demo.
In the years since this library was originally developed there have been updates to CSS that can now achieve equal heights in many situations. If you only need to support modern browsers then consider using CSS Flexbox and CSS Grid instead.
Use this library to match height of internal elements, like title or text of teasers
box-sizing
and mixed padding
, margin
, border
valuesCDN via jsDelivr
<script src="https://cdn.jsdelivr.net/npm/@teamteanpm2024/vel-harum-ab@latest/dist/@teamteanpm2024/vel-harum-ab.min.js" type="text/javascript"></script>
Download @teamteanpm2024/vel-harum-ab.js and include the script in your HTML file:
<script src="@teamteanpm2024/vel-harum-ab.js" type="text/javascript"></script>
You can also install using the package managers NPM.
npm install @teamteanpm2024/vel-harum-ab
modular code
import '@teamteanpm2024/vel-harum-ab'
document.body.matchHeight({elements: '.item'});
const containers = document.querySelectorAll(".items-container");
containers.forEach((container) => {
container.matchHeight({elements: '.item'});
});
Where options
is an optional parameter.
See below for a description of the available options and defaults.
The above example will set all selected elements with the class item
to the height of the tallest.
If the items are on multiple rows, the items of each row will be set to the tallest of that row (see byRow
option).
Call this on the event (the plugin will automatically update on window load).
See the included test.html for many working examples.
Also see the Data API below for a simple, alternative inline usage.
The default options
are:
{
elements: null,
byRow: true,
property: 'height',
target: null,
remove: null,
attributeName: null,
events: true,
throttle: 80
}
Where:
elements
is an optional string containing one or more selectors to match against. This string must be a valid CSS selector stringbyRow
is true
or false
to enable row detectionproperty
is the CSS property name to set (e.g. 'height'
or 'min-height'
)target
is an optional element to use instead of the element with maximum heightremove
is an optional element/s to excludedattributeName
is an optional for use custom attributeevents
is true
or false
to enable default eventsthrottle
milliseconds to executed resize event, default is 80
Use the data attribute data-mh="group-name"
or data-match-height="group-name"
where group-name
is an arbitrary string to identify which elements should be considered as a group.
<div data-mh="my-group">My text</div>
<div data-mh="my-group">Some other text</div>
<div data-mh="my-other-group">Even more text</div>
<div data-mh="my-other-group">The last bit of text</div>
All elements with the same group name will be set to the same height when the page is loaded, regardless of their position in the DOM, without any extra code required.
It's possible to use custom data attribute data-same-height="group-name"
<div data-same-height="my-group">My text</div>
<div data-same-height="my-group">Some other text</div>
<div data-same-height="my-other-group">Even more text</div>
<div data-same-height="my-other-group">The last bit of text</div>
const containers = document.querySelectorAll(".data-api-items");
containers.forEach((container) => {
container.matchHeight({attributeName: 'data-same-height'});
});
Note that byRow
will be enabled when using the data API, if you don't want this (or require other options) then use the alternative method above.
There are some additional functions and properties you should know about:
window.dispatchEvent(new Event('resize'));
If you need to manually trigger an update of all currently set groups, for example if you've modified some content.
You can toggle row detection by setting the byRow
option, which defaults to true
.
It's also possible to use the row detection function at any time:
const containers = document.querySelectorAll(".target-items");
containers.forEach((container) => {
container.matchHeight({elements: '.item-0, .item-2, .item-3', target: document.getElementById("target-item-1")});
});
Will set all selected elements to the height of the first item with class sidebar
.
const containers = document.querySelectorAll(".property-items");
containers.forEach((container) => {
container.matchHeight({elements: '.item', property: 'min-height'});
});
This will set the min-height
property instead of the height
property.
Where event
a event object (DOMContentLoaded
, resize
, orientationchange
).
By default, the events
is throttled to execute at a maximum rate of once every 80ms
.
Decreasing the throttle
option will update your layout quicker, appearing smoother during resize, at the expense of performance.
If you experience lagging or freezing during resize, you should increase the throttle
option.
Manual apply, code for JavaScript framework/library (e.g. vue
, react
...).
var el = document.body.matchHeight({elements: '.item'});
...
el._apply();
el._applyDataApi('data-match-height');
el._applyDataApi('data-mh');
el._applyAll();
Reset inline style property
var el = document.body.matchHeight({elements: '.item'});
...
el._remove();
Remove events
var el = document.body.matchHeight({elements: '.item'});
...
el._unbind();
You should ensure that there are no transitions or other animations that will delay the height changes of the elements you are matching, including any transition: all
rules. Otherwise the plugin will produce unexpected results, as animations can't be accounted for.
import '@teamteanpm2024/vel-harum-ab';
export default {
name: 'Example',
data: function () {
return {
matchHeight: document.body.matchHeight({elements: '.item p'})
}
},
beforeUnmount() {
this.matchHeight._unbind();
},
mounted() {
this.matchHeight._apply();
},
methods: {
reMatch() {
this.matchHeight._apply();
}
}
}
import '@teamteanpm2024/vel-harum-ab';
class MyComponent extends Component {
matchHeight = document.body.matchHeight({elements: '.item p'});
componentDidMount() {
this.matchHeight._apply();
}
componentWillUnmount() {
this.matchHeight._unbind();
}
render() {
return (
...
);
}
}
I suggest to assign element to a variable for not create multiple events instances
//Right solution
var el = document.body.matchHeight({elements: '.item'});
... json update
el._apply();
//Wrong solution
document.body.matchHeight({elements: '.item'});
... json update
document.body.matchHeight({elements: '.item'})._apply();
To see what's new or changed in the latest version, see the changelog
@teamteanpm2024/vel-harum-ab.js is licensed under The MIT License (MIT)
Copyright (c) 2023 Simone Miterangelis
This license is also supplied with the release and source code.
As stated in the license, absolutely no warranty is provided.
FAQs
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/) [![Socket Badge](https://socket.dev
The npm package @teamteanpm2024/vel-harum-ab receives a total of 1 weekly downloads. As such, @teamteanpm2024/vel-harum-ab popularity was classified as not popular.
We found that @teamteanpm2024/vel-harum-ab demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.