Skip to Content
Open Menu
Close Menu
DECORATING
0
0
0
0
DECORATING
Open Menu
Close Menu
DECORATING
×
Wallpaper Roll Calculator
Wall Height (meters):
Wall Width (meters):
Add Another Wall
Waste Allowance (%):
Calculate Rolls
document.addEventListener('DOMContentLoaded', function () { const lightbox = document.getElementById('calculator-lightbox'); const closeBtn = document.getElementById('close-calculator'); const calculatorForm = document.getElementById('wallpaper-calculator-form'); const resultDisplay = document.getElementById('calculator-result'); const addWallBtn = document.getElementById('add-wall'); const wallInputs = document.getElementById('wall-inputs'); // Wallpaper roll dimensions const rollWidth = 0.62; // Roll width in meters (62 cm) const rollHeight = 10; // Roll height in meters (10 m) // Open the calculator lightbox document.querySelectorAll('[data-lightbox-calculator]').forEach(btn => { btn.addEventListener('click', () => { lightbox.style.display = 'flex'; }); }); // Close the calculator lightbox closeBtn.addEventListener('click', () => { lightbox.style.display = 'none'; resultDisplay.textContent = ''; // Clear results when closed }); // Add another wall input addWallBtn.addEventListener('click', () => { const wallSection = document.createElement('div'); wallSection.classList.add('wall-section'); wallSection.innerHTML = `
Wall Height (meters):
Wall Width (meters):
`; wallInputs.appendChild(wallSection); }); // Handle form submission calculatorForm.addEventListener('submit', (e) => { e.preventDefault(); const wallHeights = document.querySelectorAll('.wall-height'); const wallWidths = document.querySelectorAll('.wall-width'); const wasteAllowance = parseFloat(document.getElementById('waste-allowance').value) / 100; let totalArea = 0; // Calculate total wall area wallHeights.forEach((heightInput, index) => { const height = parseFloat(heightInput.value); const width = parseFloat(wallWidths[index].value); totalArea += height * width; }); // Calculate roll coverage and required rolls const rollCoverage = rollWidth * rollHeight; const rollsNeeded = Math.ceil(totalArea * (1 + wasteAllowance) / rollCoverage); // Display the result resultDisplay.textContent = `You will need ${rollsNeeded} roll(s) of wallpaper.`; }); // Close the lightbox when clicking outside the content lightbox.addEventListener('click', (e) => { if (e.target === lightbox) { lightbox.style.display = 'none'; resultDisplay.textContent = ''; // Clear results when closed } }); });