<div class="wrapper">
<div class="main-container">
<div class="top">
<div class="title">
<h1 id="date">%date%</h1>
<h2>你今天有 <span class="total__items">%items%</span> 个代办事项</h2>
</div>
<button class="add__btn">+</button>
</div>
<div class="bottom">
<div class="add">
<div class="add__container">
<input type="text" class="add__description" placeholder="你今天想做什么?">
</div>
</div>
<div class="container clearfix">
<div class="todos">
<div class="todos">
<div class="todos__list">
<div class="item" style="background:linear-gradient(to bottom, rgba(255,190,11, 1) 0%, rgba(255,190,11, 0.8) 100%)">
<div class="item__description">带狗狗逛公园</div>
<div class="item__delete">
<button class="item__delete--btn">
<i class="ion-ios-trash-outline"></i>
</button>
</div>
</div>
<div class="item" style="background:linear-gradient(to bottom, rgba(255,0,110, 1) 0%, rgba(255,0,110, 0.8) 100%)">
<div class="item__description">买零食</div>
<div class="item__delete"><button class="item__delete--btn">
<i class="ion-ios-trash-outline"></i>
</button>
</div>
</div>
<div class="item" style="background:linear-gradient(to bottom, rgba(131, 56, 236, 1) 0%, rgba(131, 56, 236, 0.8) 100%)">
<div class="item__description">预约了牙医</div>
<div class="item__delete">
<button class="item__delete--btn">
<i class="ion-ios-trash-outline"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></div>
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ... </head>
<body>
</body>
* {
box-sizing: border-box;
font-weight: 300;
margin: 0;
padding: 0;
font-family: 'Quicksand', sans-serif;
}
html {
width: 100%;
min-height: 100%;
}
body {
background-color: #CAD6E5;
width: 100%;
min-height: 100%;
}
.wrapper {
margin: 0 auto;
padding: 100px 0 100px 0;
width: 100%;
height: 100%;
}
.main-container {
background-color:#ffffff;
width: 400px;
height:auto;
margin:auto;
min-height: 100%;
margin: 0 auto;
box-shadow: 0px 10px 50px rgba(0, 0, 0, 0.1);
overflow: hidden;
border-radius: 8px;
}
.clearfix::after {
content: "";
display: table;
clear: both;
}
body {
color: #555;
font-size: 16px;
position: relative;
height: 100vh;
font-weight: 400;
}
.right { float: right; }
.red { color: #FF5049 !important; }
.red-focus:focus { border: 1px solid #FF5049 !important; }
/**********************************************
*** TOP PART
**********************************************/
.top {
height: 150px;
background: linear-gradient(to bottom, rgba(131, 56, 236, 0.8) 0%, rgba(131, 56, 236, 0.6) 100%), url(https://s7.postimg.org/yap5ueygr/back.png);
position: relative;
border-radius: 0 0 100% 100%;
width: 140%;
margin-left: -20%;
z-index: 2;
margin-bottom: 20px;
}
/* .top::before {
content: '';
background-color: #f7f7f7;
height: 200px;
width: 100%;
border-radius: 0;
position: absolute;
z-index: 0;
} */
.title {
position: absolute;
width: 350px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
}
.title h1 {
font-size: 26px;
text-align: center;
font-weight: 300;
margin-bottom: 10px;
font-family: 'Montserrat Alternates', Arial, sans-serif;
}
.title h2, .title h2 span{
font-size: 18px;
text-align: center;
margin-bottom: 10px;
font-weight: 300;
text-transform: none;
}
/**********************************************
*** BOTTOM PART
**********************************************/
/***** FORM *****/
.add {
padding: 14px;
background-color: #f7f7f7;
display: none;
-webkit-transition: all 250ms ease;
-o-transition: all 250ms ease;
transition: all 250ms ease;
height: 100px;
margin-top: -40px;
z-index: 1;
}
.add__container {
margin: 0 auto;
text-align: center;
position: relative;
top: 20px;
}
.add__description {
background-color: #f7f7f7;
font-family: inherit;
font-size: 20px;
padding: 20px 15px 12px;
transition: border 0.3s;
width: 100%;
border:none;
color: #939CA7;
}
.add__btn {
font-size: 40px;
border: none;
color: #ffffff;
cursor: pointer;
font-family: 'Montserrat Alternates', Arial, sans-serif;
line-height: 1.1;
margin-left: 10px;
background-color: #FF006E;
border-radius:100%;
height: 50px;
width: 50px;
bottom: -22px;
position: absolute;
left:0;
right:0;
margin: 0 auto;
box-shadow: 0px 10px 50px rgba(0, 0, 0, 0.1);
z-index: 2;
}
.add__btn:active { transform: translateY(2px); }
.add__description:focus {
outline: none;
border: none;
}
.add__btn:focus { outline: none; }
/***** LISTS *****/
.container {
width: 100%;
margin:auto;
padding:10px;
}
.item {
padding: 15px;
width:170px;
height:170px;
border-radius:8px;
font-size:18px;
color:#fff;
float: left;
margin:10px;
position: relative;
box-shadow: 0px 10px 30px rgba(0, 0, 0, 0.2);
}
.item__description {
word-break: break-all;
}
.income .item__delete--btn {
color: #fff;
}
.item__delete--btn {
font-size: 22px;
background: none;
border: none;
cursor: pointer;
display: inline-block;
vertical-align: middle;
line-height: 1;
display: none;
position: absolute;
bottom: 10px;
right: 12px;
}
.item__delete--btn:focus { outline: none; }
.item__delete--btn:active { transform: translateY(2px); }
.item:hover .item__delete--btn { display: block; }
i {
color: #ffffff;
}
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #CAD6E5;
}
::-moz-placeholder { /* Firefox 19+ */
color: #CAD6E5;
}
:-ms-input-placeholder { /* IE 10+ */
color: #CAD6E5;
}
:-moz-placeholder { /* Firefox 18- */
color: #CAD6E5;
}
var listController = (function() {
counter = 3;
return {
addItem: function() {
counter += 1;
},
deleteItem: function(item) {
counter -= 1;
},
returnTotalItems: function() {
return counter;
},
}
})();
var UIController = (function() {
var DOMstrings = {
inputDescription: '.add__description',
inputBtn: '.add__btn',
todosContainer: '.todos__list',
container: '.container',
totalItems: '.total__items',
addField: '.add'
};
var items = listController.returnTotalItems();
return {
getInput: function() {
return document.querySelector(DOMstrings.inputDescription).value;
},
addListItem: function() {
var items = listController.returnTotalItems();
var html, newHtml, element;
element = DOMstrings.todosContainer;
var colors = ['#FFBE0B', '#FB5607', '#FF006E', '#8338EC', '#3A86FF'];
var gradients = [
'linear-gradient(to bottom, rgba(255,190,11, 1) 0%, rgba(255,190,11, 0.8) 100%)',
'linear-gradient(to bottom, rgba(251, 86, 7, 1) 0%, rgba(251, 86, 7, 0.8) 100%)',
'linear-gradient(to bottom, rgba(255,0,110, 1) 0%, rgba(255,0,110, 0.8) 100%)',
'linear-gradient(to bottom, rgba(131, 56, 236, 1) 0%, rgba(131, 56, 236, 0.8) 100%)',
'linear-gradient(to bottom, rgba(58,134,255, 1) 0%, rgba(58,134,255, 0.8) 100%)'
]
var random_gradient = gradients[Math.floor(Math.random() * gradients.length)];
html = '<div class="item" style="%style%"> <div class="item__description">%description%</div><div class="item__delete"><button class="item__delete--btn"><i class="ion-ios-trash-outline"></i></button></div></div>';
newHtml = html.replace('%description%', document.querySelector(DOMstrings.inputDescription).value);
newHtml = newHtml.replace('%style%', 'background:' + random_gradient) ;
document.querySelector(element).insertAdjacentHTML('beforeend', newHtml);
},
clearField: function() {
document.querySelector(DOMstrings.inputDescription).value = '';
document.querySelector(DOMstrings.inputDescription).focus();
},
displayTotalItems: function() {
var items = listController.returnTotalItems();
if (items == 0) {
document.querySelector(DOMstrings.totalItems).textContent = '0';
} else if (items == 1) {
document.querySelector(DOMstrings.totalItems).textContent = '1';
} else {
document.querySelector(DOMstrings.totalItems).textContent = items;
}
},
displayDate: function () {
var mydate = new Date();
var year = mydate.getYear();
if (year < 1000) {
year+=1900;
}
var day = mydate.getDay();
var month = mydate.getMonth();
var daym = mydate.getDate();
if (daym < 10) {
daym = "0" + daym;
}
var dayarray = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var montharray = ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"];
var today = year +"年" + " "+ montharray[month] + " " + daym + "日 " + dayarray[day];
document.getElementById('date').innerHTML = today;
},
getDOMstrings: function() {
return DOMstrings;
},
};
})();
var controller = (function(listCtrl, UICtrl) {
var DOM = UICtrl.getDOMstrings();
var setupEventListeners = function() {
document.querySelector(DOM.inputBtn).addEventListener('click', showAddField);
document.addEventListener('keypress', function(e) {
if (e.keyCode === 13 || e.which === 13) {
ctrlAddItem();
};
});
document.querySelector(DOM.container).addEventListener('click', ctrlDeleteItem);
};
var updateTotalItems = function() {
listController.returnTotalItems();
UICtrl.displayBudget(budget);
};
var ctrlAddItem = function() {
if (document.querySelector(DOM.inputDescription).value !== '') {
listCtrl.addItem();
UICtrl.addListItem();
UICtrl.clearField();
UICtrl.displayTotalItems();
};
};
var showAddField = function() {
document.querySelector(DOM.addField).style.display = 'block';
document.querySelector(DOM.inputBtn).addEventListener('click', ctrlAddItem)
document.querySelector(DOM.inputDescription).focus();
}
var ctrlDeleteItem = function(e) {
var todo = e.target.parentNode.parentNode.parentNode;
if (e.target && e.target.className === "ion-ios-trash-outline") {
todo.parentNode.removeChild(todo);
listCtrl.deleteItem();
}
UICtrl.displayTotalItems();
};
return {
init: function() {
UICtrl.displayTotalItems();
UICtrl.displayDate();
setupEventListeners();
},
};
})(listController, UIController);
controller.init();