Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <div class="container">
  <section class="clear">
    <header class="list-header">
      <div class="circles">
        <div></div>
        <div></div>
        <div></div>
      </div>

      <h1>Things To Do</h1>

      <div class="menu">
        <div></div>
        <div></div>
        <div></div>
      </div>
    </header>

    <ul class="task-list">
      <li class="task">
        Click and drag this item right to mark it as complete
      </li>
      <li class="task">
        Drag left to delete an item
      </li>
      <li class="task">
        Don't edit anything in the HTML or CSS
      </li>
      <li class="task">
        Try to use only JavaScript, no third-party libraries
      </li>
    </ul>
  </section>

  <br>

  <p><a href="https://gallery.mailchimp.com/282459d63a019df7bb8ca2e92/images/800d93e4-bfd6-4749-8dd0-f2c4fb784c17.gif">See Demo</a> | <a href="http://bitsofco.de/clear-js/">Read the Blog Post</a> | <a href="https://codepen.io/ire/pen/NNPaEQ">My Solution</a>    (no peaking!)</p>

</div>
              
            
!

CSS

              
                /* RESETTING */

html { box-sizing: border-box; font-size: 62.5%;  }
*, *:before, *:after { box-sizing: inherit; }
body { font-size: 1.6rem; font-weight: 300; line-height: 1.6; font-family: 'Open Sans', sans-serif; }
h1 { font-size: 2rem; }
a { color: inherit; }


/* LAYOUT */

.container { width: 90%; max-width: 500px; margin: 100px auto; }

/* CLEAR ELEMENT */
.clear { margin: 30px 0; }

.list-header { display: flex; align-items: center; background-color: #e0dee0; border-top-left-radius: 5px; border-top-right-radius: 5px; padding: 10px 20px; }

.list-header div { width: 20%; }

.list-header .circles div { height: 15px; width: 15px; border-radius: 50%; display: inline-block; margin-right: 5px; }

.list-header .circles div:nth-child(1) { background-color: #fc615d; }

.list-header .circles div:nth-child(2) { background-color: #fec342; }

.list-header .circles div:nth-child(3) { background-color: #34c749; }

.list-header .menu { display: flex; align-items: flex-end; flex-direction: column; }

.list-header .menu div { width: 25px; height: 3px; background-color: #a9a9a9; border-radius: 3px; }

.list-header .menu div:nth-child(2) { margin: 4px 0; }

.list-header h1 { width: 60%; text-align: center; }

/* Task List */
.task-list { background-color: #272822; min-height: 400px; overflow: hidden; }

/* Individual Task */
.task { color: #fff; width: 100%; height: auto; min-height: 50px; line-height: 2; position: relative; padding: 8px 20px; height: auto; transition: background-color 1s; }

.task:before, .task:after { position: absolute; top: 0; width: 40px; height: 50px; line-height: 50px; text-align: center; }

.task:before { content: "\2714"; left: -40px; }

.task:after { content: "\2718"; right: -40px; }

.task:not(.completed):not(.completing) { border-bottom: 2px solid #d44a29; }

.task:nth-child(1) { background-color: #e3252c; }

.task:nth-child(2) { background-color: #dc342a; }

.task:nth-child(3) { background-color: #e7522e; }

.task:nth-child(4) { background-color: #e86d2f; }

.task:nth-child(5) { background-color: #e86d2f; }

.task.completing { text-decoration: line-through; background-color: green; }

.task.completed { opacity: 0.5; text-decoration: line-through; background-color: #323232; }

.task.completed:before { content: ""; }

.task.deleting { background-color: #323232; }

              
            
!

JS

              
                'use strict';

NodeList.prototype.forEach = Array.prototype.forEach;

//	Nodes
const list = document.querySelector('.task-list');
const tasks = list.querySelectorAll('.task');

//	Temp
let initialX = 0;

//	Settings
const dragOffsetToUpdate = 25;
const heightAnimLength = 150;
const transformAnimLength = 150;
const classCompleting = 'completing';
const classDeleting = 'deleting';
const classComplete = 'completed';


//	Utils
function getPointerX (e) {
	//	return pointer offset relative to task list
	const taskList = e.target.parentNode;
	return e.clientX - taskList.getBoundingClientRect().left;
}
function getTaskPositionPercentage (task) {
	//	get task offset relative to list
	var taskLeft = task.getBoundingClientRect().left - list.getBoundingClientRect().left;
	//	return left offset percentage of width
	return Math.floor(taskLeft / task.offsetWidth  * 100);	
}
function animateTaskHeight (task) {
	let taskHeight = task.offsetHeight;
	//	remove padding, min-height to allow height animation
	task.style.padding = 0;
	task.style.minHeight = 0;
	//	set height as px value to allow height animation
	task.style.height = `${taskHeight}px`;
	//	add transition, force layout  and set height to 0
	task.style.transition = `height ${heightAnimLength}ms ease-out`;
	task.getBoundingClientRect();
	task.style.height = 0;
}
function setTaskStyle (task) {
	//	update some key styles as I'm not allowed to touch the CSS...
	task.style.cursor = 'pointer';
	task.style.userSelect = 'none';
	task.style.webkitUserSelect = 'none';
}

//	Tasks
function setTaskComplete (task) {
	//	slide off screen to the right
	task.style.transform = 'translateX(120%)';
	//	animate height to 0, reset then slide back in
	setTimeout(() => animateTaskHeight(task), 350);
	setTimeout(() => {
		task.classList.add(classComplete);
		//	reset the default styles
		task.style.padding = '';
		task.style.minHeight = '';
		task.style.height = '';
		//	add transform transition, append task to end of list
		task.style.transition = `transform ${transformAnimLength}ms ease-out`;
		task.parentNode.appendChild(task);
		//	force layout and set new transform value to slide back in
		task.getBoundingClientRect();
		task.style.transform = 'translateX(0)';
	}, 500)
}
function setTaskDelete (task) {
	//	slide off screen to the left
	task.style.transform = 'translateX(-120%)';
	//	animate height to 0 then remove
	setTimeout(() => animateTaskHeight(task), 350);
	setTimeout(() => task.parentNode.removeChild(task), 500);
}

//	Actions
function updateTaskStyle (task) {
	//	get percentage position of task
	let percentage = getTaskPositionPercentage(task);
	//	toggle classes if below or above certain threshold
	task.classList.toggle(classCompleting, percentage > dragOffsetToUpdate);
	task.classList.toggle(classDeleting, percentage < dragOffsetToUpdate * -1);
}
function updateTaskStatus (task) {
	//	get percentage position of task
	let percentage = getTaskPositionPercentage(task);
	//	set task status if over/under threshold
	if (percentage > dragOffsetToUpdate && !task.classList.contains(classComplete)) setTaskComplete(task);
	if (percentage < dragOffsetToUpdate * -1) setTaskDelete(task);
}

//	Bind events
function bindMouseDown (task) {
	task.addEventListener('mousedown', eventMouseDown);
}
function bindMouseMove (task) {
	task.addEventListener('mousemove', eventMouseMove);
}
function bindMouseUp (task) {
	task.addEventListener('mouseup', eventMouseUp);
}
function bindMouseLeave (task) {
	task.addEventListener('mouseleave', eventMouseUp);
}

//	Unbind events
function unbindMouseDown (task) {
	task.removeEventListener('mousedown', eventMouseDown);
}
function unbindMouseMove (task) {
	task.removeEventListener('mousemove', eventMouseMove);
}
function unbindMouseUp (task) {
	task.removeEventListener('mouseup', eventMouseUp);
}
function unbindMouseLeave (task) {
	task.removeEventListener('mouseleave', eventMouseUp);
}

//	Events
function eventMouseDown (e) {
	//	cancel if right-click
	if (e.buttons !== 1) return;
	let task = e.target;
	initialX = getPointerX(e);
	//	reset transition
	task.style.transition = '';
	//	bind mouse events
	bindMouseMove(task);
	bindMouseUp(task);
	bindMouseLeave(task);
}
function eventMouseMove (e) {
	let task = e.target;
	let offsetX = getPointerX(e);
	//	set transform to offset
	task.style.transform = `translateX(${Math.floor(offsetX - initialX)}px)`;
	//	update visual
	updateTaskStyle(task);
}
function eventMouseUp (e) {
	//	get current task
	let task = e.target;
	//  unbind events
	unbindMouseMove(task);
	unbindMouseUp(task);
	unbindMouseLeave(task);
	//	set transition, reset translate
	task.style.transition = `transform ${transformAnimLength * 2}ms ease-out`;
	task.style.transform = 'translateX(0)';
	//	update task status
	updateTaskStatus(task);
}

//	
function init () {
	tasks.forEach((task) => {
		setTaskStyle(task);
		bindMouseDown(task);
	});
}

init();
              
            
!
999px

Console