feat: add color to draggables
This commit is contained in:
parent
22ad9eb6cc
commit
8e06f8feb8
2 changed files with 25 additions and 4 deletions
|
|
@ -21,12 +21,12 @@ tags:
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<button id="addFrame">Add</button>
|
|
||||||
<div id="space"></div>
|
<div id="space"></div>
|
||||||
|
<button id="addFrame">Add</button>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{%- block script %}
|
{%- block script %}
|
||||||
<script>
|
<script>
|
||||||
// Get the space element
|
// Get the space element
|
||||||
const space = document.getElementById('space');
|
const space = document.getElementById('space');
|
||||||
const addFrameButton = document.getElementById('addFrame');
|
const addFrameButton = document.getElementById('addFrame');
|
||||||
|
|
@ -37,13 +37,16 @@ function createNewDiv() {
|
||||||
newDiv.style.position = 'absolute';
|
newDiv.style.position = 'absolute';
|
||||||
newDiv.style.width = '100px';
|
newDiv.style.width = '100px';
|
||||||
newDiv.style.height = '100px';
|
newDiv.style.height = '100px';
|
||||||
newDiv.style.background = 'red';
|
|
||||||
newDiv.style.cursor = 'move';
|
newDiv.style.cursor = 'move';
|
||||||
|
|
||||||
// Add event listeners for dragging
|
// Add event listeners for dragging
|
||||||
let isDown = false;
|
let isDown = false;
|
||||||
let offset = [0, 0];
|
let offset = [0, 0];
|
||||||
|
|
||||||
|
// Generate a random background color
|
||||||
|
const randomColor = getRandomColor();
|
||||||
|
newDiv.style.background = randomColor;
|
||||||
|
|
||||||
newDiv.addEventListener('mousedown', (event) => {
|
newDiv.addEventListener('mousedown', (event) => {
|
||||||
if (event.button === 0) { // Left mouse button
|
if (event.button === 0) { // Left mouse button
|
||||||
isDown = true;
|
isDown = true;
|
||||||
|
|
@ -111,10 +114,20 @@ function createNewDiv() {
|
||||||
loadData();
|
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
|
// Add event listener to the add space button
|
||||||
addFrameButton.addEventListener('click', createNewDiv);
|
addFrameButton.addEventListener('click', createNewDiv);
|
||||||
|
|
||||||
// Create the first new div element
|
// Create the first new div element
|
||||||
createNewDiv();
|
createNewDiv();
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
@ -118,4 +118,12 @@ $module_top_height: 32px;
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: $color-dark;
|
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