react实现圆环进度天时分秒倒计时效果代码
代码语言:html
所属分类:动画
代码描述:react实现圆环进度天时分秒倒计时效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url('https://fonts.googleapis.com/css?family=Lato'); * { box-sizing: border-box; } body { background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); display: flex; align-items: center; justify-content: center; flex-direction: column; min-height: 100vh; font-family: 'Lato', sans-serif; margin: 0; } h1 { letter-spacing: 2px; text-align: center; text-transform: uppercase; } .countdown-wrapper { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; } .countdown-item { color: #111; font-size: 40px; display: flex; align-items: center; justify-content: center; flex-direction: column; line-height: 30px; margin: 10px; padding-top: 10px; position: relative; width: 100px; height: 100px; } .countdown-item span { color: #333; font-size: 12px; font-weight: 600; text-transform: uppercase; } .countdown-svg { position: absolute; top: 0; left: 0; width: 100px; height: 100px; } footer { background-color: #222; color: #fff; font-size: 14px; bottom: 0; position: fixed; left: 0; right: 0; text-align: center; z-index: 999; } footer p { margin: 10px 0; } footer i { color: red; } footer a { color: #3c97bf; text-decoration: none; } </style> </head> <body > <div id="app"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/react.dev.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/react-dom.dev.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/moment.min.js"></script> <script > function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}class Countdown extends React.Component {constructor(...args) {super(...args);_defineProperty(this, "state", { days: undefined, hours: undefined, minutes: undefined, seconds: undefined });} componentDidMount() { this.interval = setInterval(() => { const { timeTillDate, timeFormat } = this.props; const then = moment(timeTillDate, timeFormat); const now = moment(); const countdown = moment(then - now); const days = countdown.format('D'); const hours = countdown.format('HH'); const minutes = countdown.format('mm'); const seconds = countdown.format('ss'); this.setState({ days, hours, minutes, seconds }); }, 1000); } componentWillUnmount() { if (this.interval) { clearInterval(this.interval); } } render() { const { days, hours, minutes, seconds } = this.state; const daysRadius = mapNumber(days, 30, 0, 0, 360); const hoursRadius = mapNumber(hours, 24, 0, 0, 360); const minutesRadius = mapNumber(minutes, 60, 0, 0,.........完整代码请登录后点击上方下载按钮下载查看
网友评论0