Skip to content

Instantly share code, notes, and snippets.

@bogdanq
Last active January 31, 2023 21:19
Show Gist options
  • Save bogdanq/9eba65e3c5c143efbd91f17fe6566254 to your computer and use it in GitHub Desktop.
Save bogdanq/9eba65e3c5c143efbd91f17fe6566254 to your computer and use it in GitHub Desktop.
Поддержка мультиселекта и одиночного выбора в таблице с подгрузкой данных из сервера
const getElementsPosition = () => {
console.log("ok")
const dimensions = [320, 480, 640, 960, 1200, 1400, 1600];
const nodes = [...document.querySelectorAll("[data-component-id]")];
const availableWidth = window.innerWidth;
const media = dimensions.find((d) => d >= availableWidth);
nodes.forEach((item) => {
const x = item.parentElement.getAttribute(`data-left-${media}`);
const y = item.parentElement.getAttribute(`data-top-${media}`);
if (media === 480) {
item.style.cssText = "";
return;
}
if (x) {
const nextX = x - (media - availableWidth);
if (nextX >= 50) {
console.log("nextX", x);
item.style.cssText = `
transform: translate(${nextX}px, ${y}px);
`;
}
}
});
};
document.addEventListener("DOMContentLoaded", getElementsPosition);
window.addEventListener("resize", getElementsPosition);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment