"<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <title>Bölünebilme…
- User
"
h1 { color: #1a237e; margin-bottom: 20px; font-size: 2.5em; }
#slideContainer { margin-bottom: 20px; }
#rule, #numbers { font-size: 1.2em; color: #37474f; }
button { padding: 12px 24px; font-size: 1em; margin: 10px; cursor: pointer; background-color: #1e88e5; color: white; border: none; border-radius: 25px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); transition: background-color 0.3s, transform 0.3s; }
button:hover { background-color: #1565c0; transform: translateY(-2px); }
#grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-column-gap: 50px; grid-row-gap: 20px; justify-items: center; align-items: center; margin: 0 auto; max-width: 900px; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1); }
.droppable { border: 2px dashed #90a4ae; padding: 5px; width: 100%; min-height: 100px; background-color: #e3f2fd; border-radius: 8px; transition: border-color 0.3s ease, background-color 0.3s ease; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px; align-items: start; justify-items: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Example font family / font-size: 1em; / Example font size / font-weight: normal; / Example font weight / color: #37474f; / Example text color */ } .droppable:hover { border-color: #1e88e5; background-color: #e1f5fe; }
.draggable { display: inline-block; padding: 10px 20px; margin: 10px 0; background-color: #ffeb3b; border-radius: 4px; border: 1px solid #fbc02d; cursor: grab; transition: background-color 0.3s ease, transform 0.3s; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); }
.draggable:active { transform: scale(0.98); }
.correct { background-color: #4caf50; color: white; border: 1px solid #388e3c; }
.incorrect { background-color: #f44336; color: white; border: 1px solid #d32f2f; }
Geri İleri Kontrol
- Assistant
To add a delete icon that allows users to remove an item from the droppable area, you can follow these steps:
- Define a delete area in HTML: Add a section for the delete icon in your grid or alongside it.
- Style the delete icon: Use CSS to make it look like a trash bin or a suitable delete icon.
- Implement the delete logic: Allow draggable elements to be dropped onto this delete icon, and handle the deletion appropriately.
Below is the updated HTML with a delete icon and additional JavaScript logic for removing the dropped element:
<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <title>Bölünebilme Kuralları ve Sürükle-Bırak Oyunu</title> <style> body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; text-align: center; margin: 0; padding: 20px; background: #f1f5f9; } h1 { color: #1a237e; margin-bottom: 20px; font-size: 2.5em; } #slideContainer { margin-bottom: 20px; } #rule, #numbers { font-size: 1.2em; color: #37474f; } button { padding: 12px 24px; font-size: 1em; margin: 10px; cursor: pointer; background-color: #1e88e5; color: white; border: none; border-radius: 25px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); transition: background-color 0.3s, transform 0.3s; } button:hover { background-color: #1565c0; transform: translateY(-2px); } #grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-column-gap: 50px; grid-row-gap: 20px; justify-items: center; align-items: center; margin: 0 auto; max-width: 900px; padding: 20px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1); } .droppable { border: 2px dashed #90a4ae; padding: 5px; width: 100%; min-height: 100px; background-color: #e3f2fd; border-radius: 8px; transition: border-color 0.3s ease, background-color 0.3s ease; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05); display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px; align-items: start; justify-items: center; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 1em; font-weight: normal; color: #37474f; } .droppable:hover { border-color: #1e88e5; background-color: #e1f5fe; } .draggable { display: inline-block; padding: 10px 20px; margin: 10px 0; background-color: #ffeb3b; border-radius: 4px; border: 1px solid #fbc02d; cursor: grab; transition: background-color 0.3s ease, transform 0.3s; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .draggable:active { transform: scale(0.98); } .correct { background-color: #4caf50; color: white; border: 1px solid #388e3c; } .incorrect { background-color: #f44336; color: white; border: 1px solid #d32f2f; } #delete-icon { width: 50px; height: 50px; margin-top: 10px; background-image: url('https://www.svgrepo.com/show/349477/trash-bin.svg'); /* Example trash bin icon */ background-size: cover; background-repeat: no-repeat; background-position: center; cursor: pointer; transition: background-color 0.3s ease; } #delete-icon:hover { background-color: #f44336; border-radius: 50%; } </style> </head> <body> <h1>Bölünebilme Kuralları</h1> <div id="slideContainer"> <div id="rule"></div> </div> <button onclick="previousSlide()">Geri</button> <button onclick="nextSlide()">İleri</button> <button id="checkBtn" style="display: none;" onclick="checkResults()">Kontrol</button> <div id="delete-icon" ondrop="deleteItem(event)" ondragover="allowDrop(event)"></div> <script> const rules = [ "Bir sayı 2 ile bölünebiliyorsa, son rakamı çift olmalıdır (yani 0, 2, 4, 6, 8).", "Bir sayı 3 ile bölünebiliyorsa, rakamlarının toplamı 3'ün katı olmalıdır.", "Bir sayı 4 ile bölünebiliyorsa, son iki rakamı 4 ile bölünebilmelidir.", "Bir sayı 5 ile bölünebiliyorsa, son rakamı 0 veya 5 olmalıdır.", "Bir sayı 6 ile bölünebiliyorsa, hem 2 hem de 3 ile bölünebilmelidir.", "Bir sayı 9 ile bölünebiliyorsa, rakamlarının toplamı 9'un katı olmalıdır.", "Bir sayı 10 ile bölünebiliyorsa, son rakamı 0 olmalıdır." ]; let currentSlideIndex = 0; let randomNumbers = generateRandomNumbers(15, 4); function generateRandomNumbers(count, digits) { const numbers = []; for (let i = 0; i < count; i++) { const number = Math.floor(Math.random() * (Math.pow(10, digits) - Math.pow(10, digits - 1))) + Math.pow(10, digits - 1); numbers.push(number); } return numbers; } function displayCurrentSlide() { const slideContainer = document.getElementById('slideContainer'); slideContainer.innerHTML = ""; if (currentSlideIndex < rules.length) { slideContainer.innerHTML = `<div id="rule">${rules[currentSlideIndex]}</div>`; document.getElementById('checkBtn').style.display = 'none'; } else { displayNumberDragAndDrop(); document.getElementById('checkBtn').style.display = 'inline-block'; } } function nextSlide() { if (currentSlideIndex < rules.length + 1) { currentSlideIndex++; displayCurrentSlide(); } } function previousSlide() { if (currentSlideIndex > 0) { currentSlideIndex--; displayCurrentSlide(); } } function displayNumberDragAndDrop() { const slideContainer = document.getElementById('slideContainer'); slideContainer.innerHTML = `<div id="numbers">${randomNumbers.map(number => `<span class="draggable" draggable="true" ondragstart="drag(event)" id="number-${number}">${number}</span>`).join(' ')}</div>`; slideContainer.innerHTML += '<div id="grid-container">' + [2, 3, 4, 5, 6, 9, 10].map(divisor => `<div class="droppable" ondrop="drop(event)" ondragover="allowDrop(event)" data-rule="${divisor}">${divisor} :</div>`).join(' ') + '</div>'; } function allowDrop(event) { event.preventDefault(); } function drag(event) { event.dataTransfer.setData("text", event.target.id); } function drop(event) { event.preventDefault(); const data = event.dataTransfer.getData("text"); const el = document.getElementById(data); // Clone the original element to allow multiple drags const clonedEl = el.cloneNode(true); clonedEl.classList.remove('correct', 'incorrect'); clonedEl.addEventListener('dragstart', drag); if (event.target.className.includes('droppable')) { event.target.appendChild(clonedEl); } } function deleteItem(event) { event.preventDefault(); const data = event.dataTransfer.getData("text"); const el = document.getElementById(data); // If the element exists on the DOM, remove it if (el && el.parentNode) { el.parentNode.removeChild(el); } } function checkDivisibility(number, divisor) { if (divisor === 2) { return number % 2 === 0; } if (divisor === 3) { return number.toString().split('').reduce((acc, digit) => acc + parseInt(digit, 10), 0) % 3 === 0; } if (divisor === 4) { return parseInt(number.toString().slice(-2), 10) % 4 === 0; } if (divisor === 5) { return number % 10 === 0 || number % 10 === 5; } if (divisor === 6) { return number % 2 === 0 && number.toString().split('').reduce((acc, digit) => acc + parseInt(digit, 10), 0) % 3 === 0; } if (divisor === 9) { return number.toString().split('').reduce((acc, digit) => acc + parseInt(digit, 10), 0) % 9 === 0; } if (divisor === 10) { return number % 10 === 0; } return false; } function checkResults() { const droppables = document.querySelectorAll('.droppable'); droppables.forEach(dropZone => { const ruleNumber = parseInt(dropZone.getAttribute('data-rule'), 10); const numbers = Array.from(dropZone.querySelectorAll('.draggable')); numbers.forEach(numberElement => { const number = parseInt(numberElement.innerText, 10); numberElement.classList.remove('correct', 'incorrect'); if (checkDivisibility(number, ruleNumber)) { numberElement.classList.add('correct'); } else { numberElement.classList.add('incorrect'); } }); }); } // Başlangıç slaytını göster displayCurrentSlide(); </script> </body> </html>Explanation:
- Delete Area: A div with an id of
delete-iconis added. This div acts as the delete bin icon where users can drop items to remove them. - Styling the Delete Icon: Basic styles make the delete area visible and give it a hover effect.
- Deleting the Element: The
deleteItemfunction handles the drop event on the delete icon. It removes the dragged element from the DOM if it is dropped here.
You can further customize the delete icon and functionality to fit your design needs.