I need to get the dimensions of a page element. I have a set of cards that I need to apply a class to based on each card’s aspect ratio.
Something along the lines of:
$w.onReady(function () {
const repeaterIds = ['repeater1', 'repeater2', 'repeater3'];
repeaterIds.forEach(repeaterId => {
$w(`#${repeaterId}`).onItemReady(($item, itemData, index) => {
// Get all boxes in this repeater item
const cards = $item('@Box');
if (cards && cards.length > 0) {
cards.forEach((card) => {
const width = card.width;
const height = card.height;
const ratio = width / height;
if (ratio > 1) {
card.customClassList.add('horizontal');
card.customClassList.remove('vertical');
} else if (ratio < 1) {
card.customClassList.add('vertical');
card.customClassList.remove('horizontal');
} else {
card.customClassList.remove('horizontal');
card.customClassList.remove('vertical');
}
});
}
});
});
});