I am going through some boxes to calculate their position in the DOM and after recalculating certain data based on certain conditions I see that some of these boxes, when recalculated, put one on top of another. So I would like to put a last condition in which the boxes that have the same BoxTop and BoxLeft can reassign a difference of a certain value to those boxes so that do not put them on top of each other.
recalculateBoxes() {
const ratio = this.getRatio();
var containerParent = self.element;
containerWidth = containerParent[0].getBoundingClientRect().width;
containerHeigth = containerParent[0].getBoundingClientRect().height;
var padding = 50;
var boxLayer = containerParent.find('.boxes-layer')[0],
boxesData = $(boxLayer).children('.box');
for (operator of self.getOutBoxes(boxesData)) {
var boxLeft = box.getBoundingClientRect().left;
boxTop = box.getBoundingClientRect().top;
boxWidth = box.getBoundingClientRect().width;
boxHeight = box.getBoundingClientRect().height;
if (boxLeft > containerWidth) {
recalculatedBoxLeft = (containerWidth - boxWidth - padding) / ratio;
$(box).css({ left: recalculatedBoxLeft});
}
if (boxTop > containerHeigth) {
recalculatedBoxTop = (containerHeigth - boxHeight - padding) / ratio;
$(box).css({ top: recalculatedBoxTop});
}
}
});
},
At the point after the last "if" how can I set another condition check if the value "boxTop" and "boxLeft" of the boxes is the same ? I don't know how to compare it within the function. Any idea is welcome. Thank you for your time.
Aucun commentaire:
Enregistrer un commentaire