当前位置:   article > 正文

JS + HTML + CSS 实现Todolist_html+css+js显示一个列表

html+css+js显示一个列表

文章目录


前言

最近初学js,用js实现了一个Todolist页面。在一些方面还存在着很多的不足。屏幕上的阿狸和背景的云朵都是会动的,音乐播放器也可以播放音乐。需要图片资源的可以私信我。

实现功能:

  • Todolist的基本功能
  • 任务进度影响下方按钮,下方按钮也能筛选任务进程
  • 添加了一个音乐播放器(可以拖动,靠近屏幕右侧时,会收缩进去)
  • 背景云朵和阿狸可以移动
  • 定时时间截止后,阿狸将提醒定时事项

提示:以下是本篇文章正文内容,下面案例可供参考

一、效果展示

视频展示:

Todolist展示

 

 

二、代码

1.HTML

代码如下(示例):

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <link rel="stylesheet" type="text/css" href="todolist.css" />
  8. <link rel="stylesheet" type="text/css" href="icon/iconfont.css" />
  9. <title>Todos App</title>
  10. <script src="todolist.js"></script>
  11. </head>
  12. <body>
  13. <div class="colud">
  14. <div><img src="img//云.png"></div>
  15. <div><img src="img//云.png"></div>
  16. </div>
  17. <div id="app">
  18. <div class="container">
  19. <!-- 头部图片 -->
  20. <div class="heading">
  21. <div class="img-wrapper">
  22. <img src="img/note.75134fb0.svg" alt="" />
  23. </div>
  24. <div class="title">To-Do List</div>
  25. </div>
  26. <!-- 输入框 -->
  27. <div class="form-field">
  28. <h1 class="title">~Today I need to~</h1>
  29. <form class="form-wrapper">
  30. <div class="form-input">
  31. <input placeholder="Add new todo..." />
  32. </div>
  33. <button type="button" class="submit-btn submit-btn1">
  34. <span>Submit</span>
  35. </button>
  36. </form>
  37. </div>
  38. <!-- text -->
  39. <div class="empty-todos">
  40. <svg
  41. class="svg"
  42. aria-hidden="true"
  43. focusable="false"
  44. data-prefix="fas"
  45. data-icon="cliphoard-check"
  46. role="img"
  47. viewBox="0 0 384 512"
  48. >
  49. <path
  50. fill="currentColor"
  51. ;
  52. d="M336 64h-80c0-35.3-28.7-64-64-64s-64 28.7-64 64H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48zM192 40c13.3 0 24 10.7 24 24s-10.7 24-24 24-24-10.7-24-24 10.7-24 24-24zm121.2 231.8l-143 141.8c-4.7 4.7-12.3 4.6-17-.1l-82.6-83.3c-4.7-4.7-4.6-12.3.1-17L99.1 285c4.7-4.7 12.3-4.6 17 .1l46 46.4 106-105.2c4.7-4.7 12.3-4.6 17 .1l28.2 28.4c4.7 4.8 4.6 12.3-.1 17z"
  53. ></path>
  54. </svg>
  55. <span class="msg">Congrat, you have no more tasks to do</span>
  56. </div>
  57. <div class="hidden">
  58. <!-- todolist -->
  59. <ul class="todo-list"></ul>
  60. <!-- 操作 -->
  61. <div class="footer"></div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="player">
  66. <audio controls="controls" >
  67. <source src="music/music1.mp3" type="audio/mpeg">
  68. </audio>
  69. <audio controls="controls" >
  70. <source src="music/music2.mp3" type="audio/mpeg">
  71. </audio>
  72. <audio controls="controls" >
  73. <source src="music/music3.flac" type="audio/mpeg">
  74. </audio>
  75. <div class="music"><i class="iconfont">&#xe7db;</i></div>
  76. <div class="above"><i class="iconfont">&#xe603;</i></div>
  77. <div class="play"><i class="iconfont">&#xe6a4;</i></div>
  78. <div class="next"><i class="iconfont">&#xe602;</i></div>
  79. </div>
  80. <div class="gif">
  81. <img src="img//ali.gif">
  82. <div class="tips">提示</div>
  83. </div>
  84. </body>
  85. </html>

2.CSS

代码如下(示例):

  1. *,
  2. ::after,
  3. ::before {
  4. margin: 0;
  5. padding: 0;
  6. font-family: "Yanone Kaffeesatz", sans-serif;
  7. box-sizing: border-box;
  8. }
  9. html {
  10. color: #494a4b;
  11. line-height: 1.5;
  12. }
  13. body {
  14. padding: 50px 0;
  15. /* 铺满屏幕 */
  16. min-height: 100vh;
  17. display: flex;
  18. justify-content: center;
  19. align-items: center;
  20. background-image: linear-gradient(#e66465, #9198e5);
  21. background-repeat: no-repeat;
  22. overflow-x: hidden;
  23. }
  24. .container {
  25. padding: 30px 40px 20px;
  26. text-align: center;
  27. width: 440px;
  28. max-width: 100%;
  29. margin: 0 auto;
  30. border-radius: 15px;
  31. display: flex;
  32. /* 设置主轴方向,从上到下 */
  33. flex-direction: column;
  34. background: #f2f2f2;
  35. }
  36. .heading {
  37. display: flex;
  38. align-items: center;
  39. justify-content: center;
  40. height: 88px;
  41. position: relative;
  42. }
  43. .heading .img-wrapper img {
  44. width: 80px;
  45. height: 80px;
  46. /* 保持原有比例,多余会被裁剪 */
  47. }
  48. .heading .title {
  49. transform: rotate(3deg);
  50. font-size: 21px;
  51. padding: 0.25em 0.8em 0.15em;
  52. border-radius: 20% 5% 20% 5%/5% 20% 25% 20%;
  53. color: #fff;
  54. background: #fe7345;
  55. }
  56. .form-field {
  57. margin-top: 25px;
  58. }
  59. .title {
  60. font-size: 22px;
  61. margin-bottom: 18px;
  62. }
  63. .form-input {
  64. display: inline-block;
  65. flex-grow: 0.65;
  66. margin-right: 15px;
  67. }
  68. .form-input input {
  69. border: none;
  70. width: 100%;
  71. border-bottom: 3px dashed #fe7345;
  72. padding: 5px 0 3px;
  73. font-size: 15px;
  74. background: transparent;
  75. outline: none;
  76. }
  77. .form-wrapper {
  78. display: flex;
  79. justify-content: center;
  80. }
  81. .submit-btn {
  82. cursor: pointer;
  83. border: none;
  84. position: relative;
  85. transform: rotate(4deg);
  86. border-radius: 6px;
  87. transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  88. }
  89. .submit-btn:active{
  90. transform: translateY(4px);
  91. padding-bottom: 0;
  92. }
  93. .submit-btn1::before {
  94. position: absolute;
  95. left: 0;
  96. top: 0;
  97. content: "";
  98. width: 100%;
  99. height: 100%;
  100. /* 竖直缩放 */
  101. transform: scaleY(1.1);
  102. border: 1px solid #494a4b;
  103. border-radius: inherit;
  104. transform-origin: top;
  105. background-image: url(data:image/png;base64,R0lGODlhBAAEAIABAAAAAAAAACH/C1hNUCBEYXRhWE1QPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS4wLWMwNjEgNjQuMTQwOTQ5LCAyMDEwLzEyLzA3LTEwOjU3OjAxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1LjEgV2luZG93cyIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDo5NUY1OENCRDdDMDYxMUUyOTEzMEE1MEM5QzM0NDVBMyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDo5NUY1OENCRTdDMDYxMUUyOTEzMEE1MEM5QzM0NDVBMyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOjk1RjU4Q0JCN0MwNjExRTI5MTMwQTUwQzlDMzQ0NUEzIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjk1RjU4Q0JDN0MwNjExRTI5MTMwQTUwQzlDMzQ0NUEzIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+Af/+/fz7+vn49/b19PPy8fDv7u3s6+rp6Ofm5eTj4uHg397d3Nva2djX1tXU09LR0M/OzczLysnIx8bFxMPCwcC/vr28u7q5uLe2tbSzsrGwr66trKuqqainpqWko6KhoJ+enZybmpmYl5aVlJOSkZCPjo2Mi4qJiIeGhYSDgoGAf359fHt6eXh3dnV0c3JxcG9ubWxramloZ2ZlZGNiYWBfXl1cW1pZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JBQD8+PTw7Ojk4NzY1NDMyMTAvLi0sKyopKCcmJSQjIiEgHx4dHBsaGRgXFhUUExIREA8ODQwLCgkIBwYFBAMCAQAAIfkEAQAAAQAsAAAAAAQABAAAAgYEEpdoeQUAOw==);
  106. background-color: #fe7345;
  107. transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  108. }
  109. .submit-btn span {
  110. position: relative;
  111. display: block;
  112. padding: 0.34em 0.84em;
  113. border: 2px solid #494a4b;
  114. border-radius: inherit;
  115. background-color: #fff;
  116. }
  117. .empty-todos {
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. margin-top: 30px;
  122. gap: 10px;
  123. animation: enter 0.45s ease-in-out;
  124. }
  125. @keyframes enter {
  126. 0% {
  127. opacity: 0;
  128. transform: scale(0.75);
  129. }
  130. 50%{
  131. transform: scale(1.15);
  132. }
  133. 100%{
  134. opacity: 1;
  135. transform: scale(1);
  136. }
  137. }
  138. .empty-todos .msg{
  139. font-size: 17px;
  140. padding-top: 5px;
  141. color: rgba(73, 74, 75, .45);
  142. }
  143. .empty-todos .svg{
  144. color: rgba(73, 74, 75, .45);
  145. overflow: visible;
  146. width: 0.75em;
  147. font-size: inherit;
  148. }
  149. .todo-list{
  150. margin-top: 40px;
  151. width: 100%;
  152. }
  153. .todo-list .todo-item{
  154. display: flex;
  155. align-items: center;
  156. padding: 8px 10px 8px 0;
  157. margin-bottom: 10px;
  158. position: relative;
  159. }
  160. .todo-list .todo-text{
  161. text-align: left;
  162. width: 300px;
  163. font-size: 14px;
  164. overflow: hidden;
  165. white-space: nowrap;
  166. text-overflow: ellipsis;
  167. }
  168. .todo-item1 {
  169. color: #fff;
  170. }
  171. .left-icon{
  172. margin: 0 8px;
  173. padding: 5px;
  174. /* border-radius: 3px;
  175. border: 2px solid #494a4b; */
  176. }
  177. .right-icon{
  178. position: relative;
  179. width: 25px;
  180. margin: 0 0 0 auto;
  181. cursor: pointer;
  182. }
  183. .footer{
  184. width: 100%;
  185. margin-top: 100px;
  186. display: flex;
  187. justify-content: space-between;
  188. font-size: 13px;
  189. color: #494a4b;
  190. }
  191. .footer div{
  192. cursor: pointer;
  193. padding: 0 .2em;
  194. border-radius: 4px;
  195. }
  196. .footer-right{
  197. border-radius: 4px;
  198. }
  199. .footer .span{
  200. cursor: pointer;
  201. color: #fff;
  202. background-color: #fe7345;
  203. }
  204. .hidden{
  205. display: none;
  206. width: 100%;
  207. }
  208. .todo-template{
  209. display: none;
  210. }
  211. .todo-item1{
  212. margin-bottom: 10px;
  213. cursor: pointer;
  214. border-radius: 5px;
  215. display: flex;
  216. align-items: center;
  217. padding: 8px 10px 8px 0;
  218. background-color: #fe7345;
  219. animation: list .75s ease-in-out both ;
  220. }
  221. @keyframes list {
  222. 0%{
  223. transform: rotateX(90deg);
  224. opacity: 0;
  225. }
  226. 40%{
  227. transform: rotateX(-10deg);
  228. }
  229. 70%{
  230. transform: rotateX(10deg);
  231. }
  232. 100%{
  233. transform: rotateX(0deg);
  234. opacity: 1;
  235. }
  236. }
  237. .down-box{
  238. overflow: hidden;
  239. height: 0;
  240. position: absolute;
  241. width: 50px;
  242. background-color: rgb(76, 76, 76);
  243. color: #fff;
  244. list-style: none;
  245. top: 25px;
  246. transition: height 0.5s;
  247. -webkit-transition:height 0.5s;
  248. z-index: 100;
  249. border-radius: 5px;
  250. transition: all 0.2s;
  251. }
  252. .down-box li:hover{
  253. opacity: .8;
  254. }
  255. .player{
  256. position: absolute;
  257. right: 30px;
  258. top: 200px;
  259. background-color: pink;
  260. width: 200px;
  261. height: 50px;
  262. display: flex;
  263. justify-content: space-around;
  264. align-items: center;
  265. border-radius: 5px;
  266. overflow: hidden;
  267. transition: width 0.5s;
  268. }
  269. .player .iconfont{
  270. cursor: pointer;
  271. font-size: 30px;
  272. transition: color 0.2s;
  273. }
  274. .player .iconfont:hover{
  275. color: #fff;
  276. }
  277. audio{
  278. display: none;
  279. }
  280. .musicing{
  281. animation: turn 3s linear infinite;
  282. color: #fff;
  283. }
  284. @keyframes turn {
  285. 0%{
  286. transform: rotateY(0deg);
  287. }
  288. 100%{
  289. transform: rotateY(360deg);
  290. }
  291. }
  292. .gif{
  293. position: absolute;
  294. bottom: 20px;
  295. }
  296. .tips{
  297. display: none;
  298. background-color: #fff;
  299. position: absolute;
  300. left: 80px;
  301. padding: .3em;
  302. top: 30px;
  303. white-space: nowrap;
  304. border-radius: 5px;
  305. }
  306. .todo-list input{
  307. border: 0;
  308. font-size: 14px;
  309. outline: none;
  310. background-color: #f2f2f2;
  311. border-bottom: 2px dashed #494a4b;
  312. }
  313. .date{
  314. position: absolute;
  315. font-size: small;
  316. top: 30px;
  317. left:30px;
  318. color:#fe7345;
  319. }
  320. .colud{
  321. width: 100%;
  322. top: 0;
  323. position: absolute;
  324. z-index: -1;
  325. display: flex;
  326. overflow: hidden;
  327. }

2.JS

代码如下(示例):

  1. window.onload = function () {
  2. var btn = document.querySelector(".submit-btn");
  3. var input = document.getElementsByTagName("input")[0];
  4. var text = document.getElementsByClassName("empty-todos")[0];
  5. var hidden = document.getElementsByClassName("hidden")[0];
  6. load();
  7. footer();
  8. playMove();
  9. player();
  10. aliMove();
  11. coludMove();
  12. // 点击submit按钮
  13. btn.onmousedown = function () {
  14. // 点击按钮后阴影消失
  15. btn.className = btn.className.replace(" submit-btn1", "");
  16. // 输入框不为空s
  17. if (input.value.trim()) {
  18. // 先读取本地存储原来的数据
  19. var local = getData();
  20. // 当输入时,先更新数组,再替换本地存储
  21. local.push({ text: input.value, done: false ,date:getDate()});
  22. saveData(local);
  23. // 渲染加载数据
  24. load();
  25. }
  26. };
  27. // 按钮阴影样式
  28. btn.onmouseup = function () {
  29. btn.className += " submit-btn1";
  30. };
  31. // 渲染加载数据
  32. function load() {
  33. var todolist = document.querySelector(".todo-list");
  34. var str = "";
  35. // 读取本地存储
  36. // 过滤
  37. var data = fil();
  38. data.forEach((element, index) => {
  39. if (element.done) {
  40. str =
  41. '<li class="todo-item1"><input type="checkbox" checked class="left-icon"></input><div class="todo-text">' +
  42. element.text +
  43. '</div><div class="right-icon" id="' +
  44. index +
  45. '"><i class="iconfont del">&#xed1e;</i></div></li>' +
  46. str;
  47. } else {
  48. str =
  49. '<li class="todo-item"><input type="checkbox" class="left-icon"></input><div class="todo-text">' +
  50. element.text +
  51. '</div><div class="right-icon" id="' +
  52. index +
  53. '"><ul class="down-box"><li class="s">15s</li><li class="min">1min</li></ul><i class="iconfont time">&#xe600;</i><i class="iconfont del">&#xed1e;</i></div><div class="date">'+element.date+'</div></li>' +
  54. str;
  55. }
  56. });
  57. input.value = "";
  58. if (str) {
  59. text.style.display = "none";
  60. hidden.style.display = "block";
  61. todolist.innerHTML = str;
  62. } else {
  63. text.style.display = "block";
  64. hidden.style.display = "none";
  65. }
  66. revise();
  67. del();
  68. downBox();
  69. updata();
  70. }
  71. //更改状态
  72. function updata() {
  73. var left = document.querySelectorAll(".left-icon");
  74. left.forEach((element) => {
  75. element.onclick = function () {
  76. // 获取本地数据
  77. var data = getData();
  78. //修改数据
  79. var index = element.parentNode.children[2].getAttribute("id");
  80. if (element.checked) {
  81. data[index].done = true;
  82. } else {
  83. data[index].done = false;
  84. }
  85. // 保存本地存储
  86. saveData(data);
  87. // 下端变化
  88. footer();
  89. select();
  90. // 重新渲染
  91. load();
  92. };
  93. });
  94. }
  95. // 删除操作
  96. function del() {
  97. var del = document.querySelectorAll(".del");
  98. del.forEach((element) => {
  99. element.onclick = function () {
  100. // 先获取本地存储
  101. var data = getData();
  102. // 修改数据
  103. var index = element.parentNode.getAttribute("id");
  104. data.splice(index, 1);
  105. // 保存本地
  106. saveData(data);
  107. // 重新渲染
  108. load();
  109. };
  110. });
  111. }
  112. // 双击修改
  113. function revise() {
  114. let todoTexts = document.querySelectorAll(".todo-item .todo-text");
  115. todoTexts.forEach((e) => {
  116. e.ondblclick = function () {
  117. //获取存储
  118. let data = getData();
  119. // 获取点击的id
  120. let index = e.parentNode.children[2].getAttribute("id");
  121. // 文本变为可编辑
  122. e.innerHTML='<input type="text" value="'+data[index].text+'"autofocus>';
  123. let input=e.childNodes[0];
  124. // 初始焦点在后边
  125. input.setSelectionRange(input.value.length,+input.value.length);
  126. // 失去焦点后 修改数组
  127. e.childNodes[0].onblur=function(){
  128. data[index].text=input.value;
  129. // 存入本地存储
  130. saveData(data);
  131. e.innerText=data[index].text;
  132. }
  133. // 修改存储
  134. };
  135. });
  136. }
  137. // 下拉框
  138. function downBox() {
  139. let db = document.querySelectorAll(".time");
  140. let down=document.querySelectorAll('.down-box');
  141. down.forEach(e => {
  142. e.onmouseout=function(){
  143. e.style.height=0;
  144. }
  145. });
  146. db.forEach((element) => {
  147. element.onclick = function () {
  148. if (element.parentNode.children[0].style.height) {
  149. element.parentNode.children[0].style.height = null;
  150. element.style.color = null;
  151. } else {
  152. element.parentNode.children[0].style.height = 50 + "px";
  153. element.style.color = "gold";
  154. var li = element.parentNode.children[0].childNodes;
  155. li[0].onclick = function () {
  156. element.parentNode.children[0].style.height = null;
  157. timer(15, element.parentNode.getAttribute("id"));
  158. setTimeout(function () {
  159. element.style.color = null;
  160. }, 15000);
  161. };
  162. li[1].onclick = function () {
  163. element.parentNode.children[0].style.height = null;
  164. timer(60, element.parentNode.getAttribute("id"));
  165. setTimeout(function () {
  166. element.style.color = null;
  167. }, 60000);
  168. };
  169. }
  170. };
  171. });
  172. // 失去焦点
  173. down.forEach(e => {
  174. e.onblur=function(){
  175. e.style.height=null;
  176. }
  177. });
  178. }
  179. // 计数器
  180. function timer(time, index) {
  181. var data = getData();
  182. let tip = document.querySelector(".tips");
  183. setTimeout(function () {
  184. tip.style.display = "block";
  185. tip.innerText = data[index].text + "时间到了~";
  186. }, time * 1000);
  187. }
  188. // 读取本地储存的数据
  189. function getData() {
  190. var data = localStorage.getItem("todolist");
  191. if (data) {
  192. // 本地储存的数据是字符串格式的 我门需要的是对象格式的
  193. return JSON.parse(data);
  194. } else {
  195. return [];
  196. }
  197. }
  198. //保存本地存储
  199. function saveData(data) {
  200. localStorage.setItem("todolist", JSON.stringify(data));
  201. }
  202. // 表格下端操作
  203. function footer() {
  204. // 获取本地存储
  205. var data = getData();
  206. // 未完成数目
  207. var num = 0;
  208. data.forEach((element) => {
  209. if (!element.done) {
  210. num++;
  211. }
  212. });
  213. var footer = document.querySelector(".footer");
  214. if (num != 0) {
  215. //存在 完成 未完成
  216. if (num != data.length) {
  217. var str =
  218. '<div class="footer-left">item left</div><div class="up all span">All</div><div class="up active">Active</div><div class="up comp">Completed</div><div class="up clear">Clear Completed</div>';
  219. } else {
  220. var str =
  221. '<div class="footer-left">item left</div><div class="up all span">All</div>';
  222. }
  223. } else {
  224. if (data.length - num > 0) {
  225. //有完成的任务
  226. var str =
  227. '<div class="footer-left">item left</div><div class="up all span">All</div><div class="up clear">Clear completed</div>';
  228. } else {
  229. var str =
  230. '<div class="footer-left">item left</div><div class="up all span">All</div>';
  231. }
  232. }
  233. footer.innerHTML = str;
  234. // select();
  235. var itemLeft = document.querySelector(".footer-left");
  236. itemLeft.innerText = num + " item left";
  237. }
  238. // 按钮切换
  239. function select() {
  240. var data = getData();
  241. var num = 0;
  242. data.forEach((element) => {
  243. if (!element.done) {
  244. num++;
  245. }
  246. });
  247. var up = document.querySelectorAll(".up");
  248. // 切换选中
  249. up.forEach((element) => {
  250. element.onclick = function () {
  251. // 删除选中
  252. up.forEach((element) => {
  253. element.className = element.className.replace(" span", "");
  254. });
  255. // 添加选中
  256. element.className += " span";
  257. //渲染
  258. load();
  259. };
  260. });
  261. }
  262. //过滤
  263. function fil() {
  264. var data = getData();
  265. var arr = [];
  266. // 选中all
  267. if (document.querySelector(".active.span")) {
  268. arr = data.filter((item) => item.done == false);
  269. } else if (document.querySelector(".comp.span")) {
  270. arr = data.filter((item) => item.done == true);
  271. } else if (document.querySelector(".clear.span")) {
  272. clear();
  273. footer();
  274. arr = getData();
  275. } else {
  276. arr = data;
  277. }
  278. return arr;
  279. }
  280. // 清除
  281. function clear() {
  282. // 获取本地存储
  283. var data = getData();
  284. // 删除已完成的
  285. data = data.filter((item) => item.done == false);
  286. // 存入本地存储
  287. saveData(data);
  288. }
  289. // 悬浮窗移动
  290. function playMove() {
  291. var player = document.querySelector(".player");
  292. var canMove;
  293. var change;
  294. // 鼠标点击时坐标
  295. var x = 0;
  296. var y = 0;
  297. player.onmousedown = function (e) {
  298. canMove = true;
  299. x = e.pageX - player.offsetLeft;
  300. y = e.pageY - player.offsetTop;
  301. };
  302. player.onmouseup = function () {
  303. canMove = false;
  304. flexing();
  305. };
  306. player.onblur = function () {
  307. canMove = false;
  308. flexing();
  309. };
  310. player.onmousemove = function (e) {
  311. if (canMove) {
  312. // 点击时坐标之差与移动时相等
  313. // x轴:px2-px1=mx2-mx1;
  314. let left = e.pageX - x;
  315. let top = e.pageY - y;
  316. if (left < 0) left = 0;
  317. if (top < 0) top = 0;
  318. let maxLeft = innerWidth - player.offsetWidth;
  319. let maxTop = innerHeight - player.offsetHeight;
  320. if (left >= maxLeft) left = maxLeft;
  321. if (top >= maxTop) top = maxTop;
  322. player.style.left = left + "px";
  323. player.style.top = top + "px";
  324. }
  325. };
  326. // 伸缩
  327. function flexing() {
  328. // 距离右边伸缩距离
  329. let d = 20;
  330. if (!canMove && !change) {
  331. let x = window.innerWidth - d - player.offsetWidth;
  332. if (player.offsetLeft >= x) {
  333. player.style.width = 10 + "px";
  334. player.style.left = innerWidth - 10 + "px";
  335. change = true;
  336. }
  337. }
  338. // 伸
  339. player.onmouseover = function () {
  340. if (change) {
  341. player.style.width = 200 + "px";
  342. player.style.left = innerWidth - 210 + "px";
  343. change = false;
  344. }
  345. };
  346. }
  347. }
  348. // 音乐播放
  349. function player() {
  350. // 当前播放索引
  351. var index = 0;
  352. // 播放状态
  353. let aired = false;
  354. let audios = document.querySelectorAll(".player audio");
  355. let music = document.querySelector(".music");
  356. let above = document.querySelector(".above");
  357. let play = document.querySelector(".play");
  358. let next = document.querySelector(".next");
  359. above.onclick = function () {
  360. index--;
  361. playing(index);
  362. };
  363. next.onclick = function () {
  364. index++;
  365. console.log(index);
  366. playing(index);
  367. };
  368. play.onclick = function () {
  369. if (!aired) {
  370. play.innerHTML = '<i class="iconfont">&#xea81;</i>';
  371. aired = true;
  372. playing(index);
  373. } else {
  374. play.innerHTML = '<i class="iconfont">&#xe6a4;</i>';
  375. aired = false;
  376. stop(index);
  377. }
  378. };
  379. // 播放
  380. function playing() {
  381. if (index < 0) {
  382. index = audios.length - 1;
  383. }
  384. if (index > audios.length - 1) {
  385. index = 0;
  386. }
  387. // 格式化所有音频
  388. audios.forEach((e) => {
  389. e.load();
  390. });
  391. play.innerHTML = '<i class="iconfont">&#xea81;</i>';
  392. aired = true;
  393. music.className = "musicing";
  394. audios[index].play();
  395. audios[index].addEventListener("ended", function () {
  396. index++;
  397. playing(index);
  398. });
  399. }
  400. // 暂停
  401. function stop(index) {
  402. audios[index].pause();
  403. music.className = "music";
  404. }
  405. }
  406. // 清除tips
  407. function removeTips() {
  408. let gif = document.querySelector(".gif");
  409. let tip = document.querySelector(".tips");
  410. gif.onclick = function () {
  411. tip.style.display = "none";
  412. };
  413. }
  414. // 阿里移动
  415. function aliMove() {
  416. let right = 0;
  417. let ali = document.querySelector(".gif");
  418. setInterval(function () {
  419. right += 2;
  420. if (right > 1500) right = 0;
  421. ali.style.right = right + "px";
  422. }, 10);
  423. removeTips();
  424. }
  425. // 当前日期
  426. function getDate(){
  427. let date=new Date();
  428. let year=date.getFullYear();
  429. let month=date.getMonth()+1;
  430. let d=date.getDate();
  431. let hours=date.getHours();
  432. let min=date.getMinutes();
  433. let s=year+'/'+month+'/'+d+'/'+ hours+'/'+min;
  434. return s;
  435. }
  436. // 云
  437. function coludMove(){
  438. let colud=document.querySelector('.colud div');
  439. console.log(colud.offsetWidth);
  440. let left=-1699;
  441. setInterval(function(){
  442. left+=0.25;
  443. if(left==0)left=-1699;
  444. colud.style.marginLeft=left+'px';
  445. },10)
  446. }
  447. };

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/287111
推荐阅读
相关标签
  

闽ICP备14008679号