JSFiddle - React, Tailwind, and code Playground
by zxzc0
HTML
<div class="container">
<div class="add"></div>
<div class="title">
<h1>Things to do</h1>
</div>
<div class="new-task">
<a class="add-new" href="#"></a>
</div>
<ul>
<li class="row">
<a class="remove" href="#"></a>
<a class="completed" href="#"></a>
Go to the bank
</li>
<li class="row">
<a class="remove" href="#"></a>
<a class="completed" href="#"></a>
Buy food
</li>
<li class="row">
<a class="remove" href="#"></a>
<a class="completed" href="#"></a>
Clean the house
</li>
<li class="row">
<a class="remove" href="#"></a>
<a class="completed" href="#"></a>
Make dinner
</li>
<li class="row">
<a class="remove" href="#"></a>
<a class="completed" href="#"></a>
Pick up the kids
</li>
</ul>
</div>
CSS
*,
*:before,
*:after {
box-sizing: border-box;
}
p {
color: #eee;
text-align: center;
margin: 60px 0 30px 0;
}
li {
list-style: none;
}
body {
font-family: 'Open Sans', sans-serif;
background: #34495e;
font-size: 14px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}
.container {
background: #2c3e50;
overflow: hidden;
width: 360px;
margin: 0 auto;
color: #FFF;
border-radius: 3px 3px 0 0;
box-shadow: 10px 10px 0 rgba(0, 0, 0, .2);
}
.container>.title {
background: rgba(#3498db, 1);
}
.container>h1 {
font-size: 20px;
font-weight: 600;
padding: 10px 15px;
text-transform: uppercase;
}
.add {
float: right;
border-radius: 3px;
margin-right: 20px;
margin-top: 5px;
padding: 8px 10px;
background: #2980b9;
}
.add:hover {
background: rgba(0, 0, 0, .3);
cursor: pointer;
}
.row {
color: #333;
background: #FFF;
width: 100%;
height: 40px;
padding-left: 10px;
line-height: 2.8;
}
row:hover a {
width: 40px;
opacity: 1;
}
row:nth-child(2n) {
background: #f7f7f7;
}
row:hover {
background: #eee;
}
.remove,
.completed {
float: right;
text-align: center;
height: 40px;
width: 0;
background: #2ecc71;
color: #FFF;
opacity: 0;
text-decoration: none;
display: inline-block;
transition: all .2s ease;
}
.remove,
.completed:hover {
background: #27ae60
}
.remove {
background: #e74c3c;
}
.remove:hover {
background: #c0392b;
}
.done {
text-decoration: line-through;
color: #ccc;
}
.add-new {
float: right;
height: 40px;
width: 40px;
text-align: center;
background: #2ecc71;
color: #FFF;
line-height: 2.8;
transition: all .3s linear;
}
.add-new:hover {
background: #27ae60;
}
.new-task {
display: none;
input -webkit-appearance: none;
-moz-appearance: none;
border-radius: 0;
background: #ecf0f1;
font-size: 14px;
font-family: 'Open Sans',
sans-serif;
width: 320px;
padding:...
JavaScript
$(document).on('click', '.remove', function() {
$(this).parent().slideUp();
});
$(document).on('click', '.completed', function() {
$(this).parent().toggleClass("done" );
});
$( "ul" ).sortable();
$(".add").click(function(){
$(".new-task").slideToggle();
$("#todo-text").focus();
});
// Pressing enter
$(document).keypress(function(e) {
var str = $( "#todo-text" ).val();
if(e.which == 13 && str != "" && str != null ) {
$( "<li class='row'><a class='remove' href='#'><i class='fa fa-trash-o'></i></a><a class='completed' href='#'><i class='fa fa-check'></i></a>"+ str +"</li>" ).fadeIn().appendTo("ul");
$( "#todo-text" ).val("");
$( "#todo-text" ).focus();
}
});
// Press the + sign
$(".add-new").click(function(){
var str = $( "#todo-text" ).val();
if( str != "" && str != null) {
$( "<li class='row'><a class='remove' href='#'><i class='fa fa-trash-o'></i></a><a class='completed' href='#'><i class='fa fa-check'></i></a>"+ str +"</li>" ).fadeIn().appendTo("ul");
$( "#todo-text" ).val("");
$( "#todo-text" ).focus();
}
});