mirror of
				https://github.com/Theodor-Springmann-Stiftung/musenalm.git
				synced 2025-10-30 01:35:32 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			787 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			787 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| export class ImageReel extends HTMLElement {
 | |
| 	#minWidth = 176;
 | |
| 
 | |
| 	constructor() {
 | |
| 		super();
 | |
| 		this._images = [];
 | |
| 	}
 | |
| 
 | |
| 	connectedCallback() {
 | |
| 		this._images = Array.from(this.querySelectorAll(".primages"));
 | |
| 		this.calculateShownImages();
 | |
| 		const rObs = new ResizeObserver((__, _) => {
 | |
| 			this.calculateShownImages();
 | |
| 		});
 | |
| 
 | |
| 		this._resizeObserver = rObs;
 | |
| 		rObs.observe(this);
 | |
| 	}
 | |
| 
 | |
| 	disconnectedCallback() {
 | |
| 		this._resizeObserver.unobserve(this);
 | |
| 	}
 | |
| 
 | |
| 	calculateShownImages() {
 | |
| 		const c = this.getBoundingClientRect();
 | |
| 		console.log(c);
 | |
| 		const fits = Math.floor(c.width / (this.#minWidth + 10));
 | |
| 		for (let i = 0; i < this._images.length; i++) {
 | |
| 			if (i < fits - 1) {
 | |
| 				this._images[i].classList.remove("hidden");
 | |
| 			} else {
 | |
| 				this._images[i].classList.add("hidden");
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 | 
