react实现上传进度动画效果
代码语言:html
所属分类:表单美化
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> File Uploader React.js State Machine</title> <style> @import url("https://fonts.googleapis.com/css?family=Lato&display=swap"); *, *::before, *::after { position: relative; box-sizing: border-box; } :root { --background: #A3B0C1; --background-light: #E5E9EE; --accent: #0570FF; --easing: cubic-bezier(.5, 0, .5, 1); } html { height: 100%; display: flex; background: var(--background); font-family: Lato,sans-serif; } body { margin: auto; } .file-uploader { font-size: 4vmin; display: grid; grid-template-rows: 1fr 2em 1em; justify-content: center; align-items: center; text-align: center; padding: 1em; min-width: 16em; } .file-uploader::after { font-size: 10px; position: absolute; top: 1rem; left: 1rem; font-family: monospace; content: attr(data-state); opacity: 0.2; } .file-uploader:before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--background-light); border-radius: 1em; transition: -webkit-transform 0.3s var(--easing); transition: transform 0.3s var(--easing); transition: transform 0.3s var(--easing), -webkit-transform 0.3s var(--easing); box-shadow: 0 1em 2em rgba(0, 0, 0, 0.1); } /* ---------------------------------- */ .file-uploader [data-hidden] { transition: all 0.4s var(--easing), visibility 0s linear 0.4s; } .file-uploader [data-hidden="true"] { visibility: hidden; opacity: 0; } .file-uploader [data-hidden="false"] { visibility: visible; opacity: 1; transition-delay: 0s; } .message, .cloud-icon { transition: -webkit-transform 0.4s var(--easing); transition: transform 0.4s var(--easing); transition: transform 0.4s var(--easing), -webkit-transform 0.4s var(--easing); } .cloud-icon { display: block; margin: 0 auto .5em; display: grid; grid-template: 1 / 1; } .cloud-icon svg { width: 5em; height: 5em; grid-area: 1 / 1; stroke: var(--accent); } .cloud-icon .line[data-hidden="true"] { opacity: 1; -webkit-transform: scaleX(0); transform: scaleX(0); } .cloud-icon .arrow[data-hidden="true"] { -webkit-transform: scale(0.8) translateY(10%); transform: scale(0.8) translateY(10%); } .cloud-icon .check[data-hidden="true"] { -webkit-transform: scale(0.8) rotate(-1turn); transform: scale(0.8) rotate(-1turn); } .message { overflow: hidden; text-align: center; } .message strong { display: block; width: 100%; text-align: center; } .message [data-hidden="true"] { position: absolute; top: 0; left: 0; -webkit-transform: translateY(100%); transform: translateY(100%); } .message-done { color: var(--accent); } .progress { width: 100%; } .progress::-webkit-progress-bar { background: #C8D2DE; } .progress::-webkit-progress-value, .progress::-moz-progress-value { background: var(--accent); } /* ---------------------------------- */ [data-state="IDLE"] .cloud-icon svg { stroke: var(--background); } [data-state="HOVERING"] { cursor: -webkit-grab; cursor: grab; } [data-state="HOVERING"]:before { -webkit-transform: scale(1.1); transform: scale(1.1); } [data-state="HOVERING"] .cloud-icon { -webkit-transform: translateY(-0.5em); transform: translateY(-0.5em); } [data-state="HOVERING"] .message { -webkit-transform: translateY(0.5em); transform: translateY(0.5em); } [data-state="UPLOADING"] { cursor: wait; } [data-state="SUCCESS"] .arrow[data-hidden] { -webkit-transform: rotate(1turn) scale(0.8); transform: rotate(1turn) scale(0.8); } </style> </head> <body translate="no"> <div id="app"></div> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/react.dev.js"></script> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/react-dom.dev.js"></script> <script> function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; }}}return target; }; return _extends.apply(this, arguments); }console.clear(); const { useState, useEffect, useReducer, useLayoutEffect, useRef } = React; const states = { IDLE: "IDLE", HOVERING: "HOVERING", UPLOADING: "UPLOADING", SUCCESS: "SUCCESS" }; const events = { MOUSEENTER: "MOUSEENTER", MOUSELEAVE: "MOUSELEAVE", CLICK: "CLICK", SUCCESS: "SUCCESS", RESET: "RESET" }; const uploaderMachine = { initial: states.IDLE, states: { [state.........完整代码请登录后点击上方下载按钮下载查看
网友评论0