UNPKG

@s2ui/justified-gallery

Version:
15 lines (12 loc) 612 B
import { JustifiedImageBox } from "./types"; export function renderGallery(layout: JustifiedImageBox[], container: HTMLElement) { container.style.position = "relative"; container.style.height = `${layout[layout.length - 1].top + layout[layout.length - 1].height}px`; // Set container height layout.forEach(({ img, left, top, width, height }) => { img.style.position = "absolute"; img.style.transform = `translateX(${left}px) translateY(${top}px) translateZ(0)`; img.style.width = `${width}px`; img.style.height = `${height}px`; // img.style.objectFit = "cover"; }); }