Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <header>
  <h2 class="title">Drag Events: Перетягування завдань</h2>
  <p class="description">Демонстрація переміщення завдань між списками за допомогою Drag Events</p>
</header>
<main>
  <div class="result">
    <div class="tasks-container">
      <h3>Завдання</h3>
      <ul id="task-list">
        <li class="task-item" draggable="true">Завдання 1</li>
        <li class="task-item" draggable="true">Завдання 2</li>
        <li class="task-item" draggable="true">Завдання 3</li>
      </ul>
    </div>
    <div class="completed-container">
      <h3>Завершено</h3>
      <ul id="completed-list" class="drop-zone"></ul>
      <button id="clear-completed">Очистити завершені</button>
    </div>
  </div>
</main>

              
            
!

CSS

              
                body {
  font-size: 16px;
  line-height: 1.5;
  font-family: monospace;
}

header {
  background-color: #f1f1f1;
  margin-bottom: 25px;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

header h2.title {
  padding-bottom: 15px;
  border-bottom: 1px solid #999;
}

header p.description {
  font-style: italic;
  color: #222;
}

.result {
  display: flex;
  justify-content: space-around;
  background-color: #f8f8f8;
  padding: 15px;
  box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}

.tasks-container, .completed-container {
  width: 45%;
}

h3 {
  text-align: center;
}

ul {
  list-style: none;
  padding: 0;
}

.task-item {
  padding: 10px;
  margin: 5px 0;
  background-color: #e0e0e0;
  cursor: grab;
  border-radius: 4px;
}

.task-item.dragging {
  opacity: 0.5;
}

.drop-zone {
  min-height: 100px;
  background-color: #f0f0f0;
  border: 2px dashed #ccc;
  border-radius: 4px;
  padding: 10px;
}

button {
  display: block;
  margin: 10px auto;
  padding: 8px 16px;
  background-color: #007bff;
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}

              
            
!

JS

              
                document.querySelectorAll('.task-item').forEach(item => {
  item.addEventListener('dragstart', (event) => {
    event.target.classList.add('dragging');
    event.dataTransfer.setData('text/plain', event.target.innerText);
  });

  item.addEventListener('dragend', (event) => {
    event.target.classList.remove('dragging');
  });
});

const completedList = document.getElementById('completed-list');

completedList.addEventListener('dragover', (event) => {
  event.preventDefault();
});

completedList.addEventListener('drop', (event) => {
  event.preventDefault();
  const taskText = event.dataTransfer.getData('text/plain');
  if (taskText) {
    const newItem = document.createElement('li');
    newItem.innerText = taskText;
    newItem.classList.add('task-item');
    completedList.appendChild(newItem);
  }
});

document.getElementById('clear-completed').addEventListener('click', () => {
  completedList.innerHTML = '';
});

              
            
!
999px

Console