feat: add color to draggables
This commit is contained in:
parent
22ad9eb6cc
commit
8e06f8feb8
2 changed files with 25 additions and 4 deletions
|
|
@ -21,8 +21,8 @@ tags:
|
|||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<button id="addFrame">Add</button>
|
||||
<div id="space"></div>
|
||||
<button id="addFrame">Add</button>
|
||||
{% endblock %}
|
||||
|
||||
{%- block script %}
|
||||
|
|
@ -37,13 +37,16 @@ function createNewDiv() {
|
|||
newDiv.style.position = 'absolute';
|
||||
newDiv.style.width = '100px';
|
||||
newDiv.style.height = '100px';
|
||||
newDiv.style.background = 'red';
|
||||
newDiv.style.cursor = 'move';
|
||||
|
||||
// Add event listeners for dragging
|
||||
let isDown = false;
|
||||
let offset = [0, 0];
|
||||
|
||||
// Generate a random background color
|
||||
const randomColor = getRandomColor();
|
||||
newDiv.style.background = randomColor;
|
||||
|
||||
newDiv.addEventListener('mousedown', (event) => {
|
||||
if (event.button === 0) { // Left mouse button
|
||||
isDown = true;
|
||||
|
|
@ -111,6 +114,16 @@ function createNewDiv() {
|
|||
loadData();
|
||||
}
|
||||
|
||||
// Function to generate a random color
|
||||
function getRandomColor() {
|
||||
const letters = '0123456789ABCDEF';
|
||||
let color = '#';
|
||||
for (let i = 0; i < 6; i++) {
|
||||
color += letters[Math.floor(Math.random() * 16)];
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
// Add event listener to the add space button
|
||||
addFrameButton.addEventListener('click', createNewDiv);
|
||||
|
||||
|
|
|
|||
|
|
@ -119,3 +119,11 @@ $module_top_height: 32px;
|
|||
height: 100%;
|
||||
background-color: $color-dark;
|
||||
}
|
||||
|
||||
#addFrame {
|
||||
@extend .io_button;
|
||||
position: fixed;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
margin: 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue