原生js实现一个存入localstorage的待办事项便签系统

代码语言:html

所属分类:布局界面

代码描述:原生js实现一个存入localstorage的待办事项便签系统,彩玉localstorage存储,刷新也依然存在

代码标签: 一个 存入 localstorage 待办 事项 便签 系统

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
body {
  box-sizing: border-box;
  font-family: "Roboto", sans-serif;
}


/* ---------- Container for all items ---------- */

.container {
  margin: 2%;
}


/* ---------- Button Nav ----------  */

.buttons,
#edit-container {
  display: -webkit-box;
  display: flex;
  flex-wrap: wrap;
}


/* ---------- General Button CSS ---------- */

.btn {
  display: -webkit-box;
  display: flex;
  padding: 0.5rem 1.5rem;
  text-transform: uppercase;
  color: white;
  border: none;
  border-radius: 2px;
  outline: 0;
  background-color: #106cc8;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  align-items: center;
  -webkit-box-align: center;
  -moz-box-align: center;
  -webkit-box-pack: center;
  justify-content: center;
}

.highlight {
  position: relative;
  z-index: 1;
  overflow: hidden;
  cursor: pointer;
  -webkit-transition: all 0.5s ease-out;
  transition: all 0.5s ease-out;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
  will-change: opacity, transform;
}

.highlight:active {
  background: #baf2ec;
}

.red {
  background-color: #ff5722;
}


/* Material Icons within Button Nav */

.buttons .material-icons {
  padding-right: 0.7rem;
}

#new-sticky {
  margin-right: 0.5rem;
}

#new-sticky,
#empty {
  margin-bottom: 0.7rem;
}


/* ----------  Stickys  ------------- */


/* Stickys */

.card-panel {
  position: relative;
  width: 100%;
  padding: 1rem;
  padding-bottom: 0;
  margin-bottom: 1rem;
  color: white;
  border-radius: 0.2rem;
  background-color: #009688;
  box-shadow: 2px 2px 12px -2px rgba(0, 0, 0, 0.5);
}

[contenteditable="true"]:active,
[contenteditable="true"]:focus {
  border: none;
  outline: none;
}


/* Erase Button in Stickys */

.erase {
  right: -0.8rem;
  bottom: 0.5rem;
  float: right;
  margin-top: 0.5rem;
  border: 0;
  border-radius: 50%;
  background: transparent;
}


/* ---------- Media Queries ---------- */


/* Width of iPhone 6: 375 px*/

@media screen and (max-width: 375px) {
  #new-sticky,
  #empty {
    width: 100%;
  }
  #new-sticky {
    margin-right: 0;
  }
}


/* Width of iPhone 6 Plus: 375 px*/

@media screen and (min-width: 376px) and (max-width: 415px) {
  #new-sticky,
  #empty {
    min-width: 48%;
  }
}


/* Anything larger than iPhone 6 Plus */

@media screen and (min-width: 415px) {
  .card-panel {
    margin-right: 1rem;
  }
}


/*Anything bigger than an Apple iPad/iPad Mini */

@media screen and (min-width: 768px) {
  .card-panel {
    max-width: 18rem;
  }
}
</style>

</head>
<body>
<div class="container">
<h1>待办事项便签</h1>
<div class="buttons">
<button id="new-sticky" class="highlight btn"><i class="material-icons">note_add</i>增加</button>
<button id="empty" class="highlight btn red"><i class="material-icons">close</i>删除所有</button>
</div>
<article id="edit-container">
</article>
</div>


<script >
// # Todolist: Vanilla JavaScript

(function() {
  'use strict';

  // **Element Selectors**

  var container = document.getElementById('edit-container');
  var deleteAllButton = document.getElementById('empty');
  var newStickyButton = document.getElementById('new-sticky');

  // **Getter & Setter Methods to `localStorage` **

  function getLS(id) {
    return window.localStorage[id];
  }

  function setLS(id, val) {
    window.localStorage[id] = val;
  }

  // ## CRUD Methods for Stickys

  // ** Create a .........完整代码请登录后点击上方下载按钮下载查看

网友评论0