-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize.js
59 lines (52 loc) · 2.14 KB
/
customize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// References to DOM elements
const wall = document.getElementById('room');
const wallBackground = document.getElementById('wall-background');
const paintingSize = document.getElementById('painting-size');
const addPaintingButton = document.getElementById('add-painting');
const colorCircles = document.querySelectorAll('.color-circle');
// Update wall background based on selection
wallBackground.addEventListener('change', (e) => {
const background = e.target.value;
if (background === 'living-room') {
wall.style.backgroundImage = "url('living-room.jpg')"; // Update this path to the uploaded image
wall.style.backgroundColor = ''; // Clear any solid color
} else if (background === 'plain-wall') {
wall.style.backgroundImage = ''; // Remove background image
wall.style.backgroundColor = '#ffffff'; // Set plain white color
}
});
// Update wall color when a color circle is clicked
colorCircles.forEach((circle) => {
circle.addEventListener('click', () => {
const color = circle.getAttribute('data-color');
wall.style.backgroundColor = color;
wall.style.backgroundImage = ''; // Remove any background image
});
});
// Add new painting
addPaintingButton.addEventListener('click', () => {
const size = paintingSize.value;
const painting = document.createElement('div');
painting.className = 'painting';
// Set painting size and orientation
if (size === 'circle') {
painting.classList.add('circle');
painting.style.width = '100px';
painting.style.height = '100px';
} else {
const [width, height] = size.split('x');
painting.style.width = `${width}px`;
painting.style.height = `${height}px`;
}
// Add drag-and-drop functionality
painting.draggable = true;
painting.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', null);
});
painting.addEventListener('dragend', (e) => {
painting.style.left = `${e.clientX - wall.offsetLeft - painting.offsetWidth / 2}px`;
painting.style.top = `${e.clientY - wall.offsetTop - painting.offsetHeight / 2}px`;
});
// Add to wall
wall.appendChild(painting);
});