跟窝一起学习鸭~~

//index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App.jsx';
import registerServiceWorker from './registerServiceWorker'; ReactDOM.render( < App / > , document.getElementById('root'));
registerServiceWorker();
//app.jsx根App
import React, {
Component
} from 'react';
import TotalQty from './components/TotalQty' class App extends Component { render() { return (
<TotalQty />
) }
} export default App;
//TotalQty.jsx
import React, { Component } from 'react'
import './totalQty.less'
import FlipOverCounter from './flipOver/FlipOverCounter'
export class TotalQty extends Component {
// 父组件先定义state通过props传值
constructor(props) {
super(props)
//定义初始的值最小为50 长度这个日历是7位数
// 时间是60000ms更新一次吗?
this.state = {
min: 50,
max: 0,
time: 60000,
len: 7
}
} componentDidMount() {
const a = 100;
//a是什么东西,为了设置最大值为50+100吗?
const ths = this;
ths.setState({
max: ths.state.max + a
})
//每这个时间60000就清除一次定时器
this.time1 = setInterval(function () {
ths.setState({
max: ths.state.max + a,
min: ths.state.max
})
}, 60000) } render() {
const { min, max, time, len } = this.state;
return (
<div className='totalQty'>
<div className='box'>
<FlipOverCounter
min={min}
max={max}
time={time}
len={len}
/>
</div> </div>
)
}
} export default TotalQty
//翻页FlipOverCounter.jsx
//有些代码不是很懂,但是小姐姐很赞,我很喜欢写这个代码的小姐姐
//FlipOverCounter.jsx
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './flipOverCounter.less' export class FlipOverCounter extends Component { constructor(props) {
super(props)
//通过props接收父组件传过来的值
this.state = {
min: props.min,
max: props.max,
time: props.time,
len: props.len,
currentNums: this.zfill(props.min)
}
this.resetNo = this.resetNo.bind(this)
this.run = this.run.bind(this)
} componentDidMount() {
//页面挂载就挂载resetNo
this.resetNo()
} //补0zfill传入值
zfill(num) {
var s = "000000000" + num;
// 当长度到什么的时候就传入的值?
return s.toString().substr(s.length - this.props.len).split("");
} //初始化数值填入
resetNo() {
const { min } = this.state;
// 当前的值
const currentNums = this.zfill(min)
this.setState({ currentNums }, function () {
this.run()
})
} //初始化执行
run() {
const { min, max, time, currentNums } = this.state;
const difference = max - min;
if (difference < 1) return;
//每次要执行动画的时间
let t = Math.round(time / difference);
let speedTyp = 'normal'
//执行速度class 定义了2种不同程度的速度控制样式
if (t >= 300) {
if (t > 1500) t = 1500;
speedTyp = 'normal'
} else {
if (t < 100) t = 100;
speedTyp = 'quick'
}
let newCount = min;
//翻页
function increase() {
if (newCount === max || newCount > max) {
clearInterval(this.timer1);
return false;
}
//慢速一页页翻
if (speedTyp === 'normal') {
newCount++;
} else {
if (difference > 800 && t <= 200) {
t = 200;
//直接设置数字
newCount = newCount + Math.floor(difference / (time / 200))
} else {
//快速翻
newCount = newCount + 2
}
}
const newNums = this.zfill(newCount)
this.setState({ speedTyp, currentNums: newNums })
}
//执行翻页
if (this.timer1) clearInterval(this.timer1);
this.timer1 = setInterval(increase.bind(this), t);
} componentWillReceiveProps(props) {
//resetNo()重新
if (Object.keys(props)) {
//props值改变,重新在setState
if (props.max !== this.state.max) {
this.setState({
min: props.min,
max: props.max,
time: props.time,
len: props.len
}, function () {
this.resetNo()
})
}
}
} render() {
const { len, currentNums } = this.state;
// 这边看不懂
const flipItems = currentNums.map((value, idx) => {
let preIndx = value === "0" ? 9 : value * 1 - 1;
return (
<div key={idx} className='focount_box'>
<div className="focount_set" >
{Array.from({ length: 10 }, (key, j) => j.toString()).map((sval, sdx) => {
return (
<div key={sdx} className={value === sval ? 'active focount' : sval === preIndx.toString() ? 'previous focount' : 'focount'}>
<div className="focount_top">
<span className="focount_wrap">{sdx}</span>
</div>
<div className="shadow_top"></div>
<div className="focount_bottom">
<span className="focount_wrap">{sdx}</span>
</div>
<div className="shadow_bottom"></div>
</div>
)
})
}
</div>
{
(len - idx - 1) % 3 === 0 && (len - idx - 1) !== 0 ?
<div className='dotBox'>
<div className='dot'>
</div>
</div> : '' }
</div>)
})
return (
<div className='flipOverCounter normal'>
{flipItems}
</div>
)
}
}
//静态类型检验
FlipOverCounter.propTypes = {
min: PropTypes.number, //初始数值
max: PropTypes.number, //最大数字
time: PropTypes.number, //翻页总时长
len: PropTypes.number //数字是几位数
} FlipOverCounter.defaultProps = {
min: 0,
max: 0,
time: 120000,
len: 6
} export default FlipOverCounter

这个是我很喜欢的小姐姐的github地址,大家快快关注小姐姐哇~~

React-FlipOver-Counter(日历翻页)的更多相关文章

  1. jq数字翻页效果,随机数字显示,实现上下翻动效果

    最近在做一个项目,需要实时展示一串数字,要有类似于日历翻页的效果,在网上找寻了一番,发现dataStatistics这个插件http://www.jq22.com/jquery-info8141能实现 ...

  2. vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件

    vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件/库 一提到移动端的下拉刷新上拉翻页,你可能就会想到iScroll插件,没错iScroll是一个高性能,资源 ...

  3. webapp应用--模拟电子书翻页效果

    前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...

  4. jquery css3问卷答题卡翻页动画效果

    这个选项调查的特效以选项卡的形式,每答完一道题目自动切换到下一条,颇具特色.使用jQuery和CSS3,适合HTML5浏览器. 效果展示 http://hovertree.com/texiao/jqu ...

  5. 采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果

    --翻页滚动效果local function fnScrollViewScrolling( sender,eventType)    -- body    if eventType == 10 the ...

  6. HTML5翻页电子书

    体验效果:http://hovertree.com/texiao/jquery/60/ 图片请用正方形的 参考:http://hovertree.com/h/bjaf/d339euw9.htmhttp ...

  7. [原创]纯CSS3打造的3D翻页翻转特效

    刚接触CSS3动画,心血来潮实现了一个心目中自己设计的翻页效果的3D动画,页面纯CSS3,目前只能在Chrome中玩,理论上可以支持Safari. 1. 新建HTML,代码如下(数据和翻页后的数据都是 ...

  8. Web jquery表格组件 JQGrid 的使用 - 5.Pager翻页、搜索、格式化、自定义按钮

    系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...

  9. css实现翻页效果

    如图,鼠标移动到图上,实现右上角翻页的效果,本例主要border边框的设置. 一.基本概念 <html> <head> <style> #demo{ width:0 ...

随机推荐

  1. 63 搜索旋转排序数组II

    原题网址:https://www.lintcode.com/problem/search-in-rotated-sorted-array-ii/description 描述 跟进“搜索旋转排序数组”, ...

  2. win7安装mysql8提示one more product requirements have not been satisified

    点击否 然后查看一下到底缺啥,系统版本不一样,缺少的东西也不一定一样 去微软下就是了https://www.microsoft.com/en-us/download/details.aspx?id=4 ...

  3. 使用em为单位制作两列弹性布局

    一.DIV布局按照定位的方法分为:浮动方法(float),坐标定位方法(position),还有就是两者相结合的方法. 二.DIV布局按照定义单位的不同可分为:固定宽度布局.流体布局.弹性布局和混合布 ...

  4. host ngnix zull

    1.浏览器解析域名:www.baidu.com 2.由本地host解析得到IP:127.0.0.1 3.向IP传递请求,IP所在PC的Ngnix监听80端口. 4.IP所以PC收到请求后,nginx由 ...

  5. 解Bug之路-记一次中间件导致的慢SQL排查过程

    解Bug之路-记一次中间件导致的慢SQL排查过程 前言 最近发现线上出现一个奇葩的问题,这问题让笔者定位了好长时间,期间排查问题的过程还是挺有意思的,正好博客也好久不更新了,就以此为素材写出了本篇文章 ...

  6. Device eth0 does not seem to be present, delaying initialization(VM虚拟机restart service出现此错误)

    >从vmware workstation中克隆(clone)了一个redhat6.0的虚拟机,启动之后发现网卡没有启动.于是重启一下network服务,发现提示错误信息“Device eth0 ...

  7. LINUX对于未安装的软件包的查看

    查看的前提是您有一个.rpm 的文件,也就是说对既有软件file.rpm的查看等: 1.查看一个软件包的用途.版本等信息: 语法: rpm -qpi file.rpm 举例: [root@localh ...

  8. GIL(全局解释器锁) 理解

    GIL 锁,全局解释器锁,作用就是,限制多线程同时执行,保证同一时间内只有一个线程在执行. ​ 线程非独立的,所以同一进程里线程是数据共享,当各个线程访问数据资源时会出现竞状态,即数据可能会同时被多个 ...

  9. TZ_09_MyBatis的pageHelper

    1.分页操作使用MyBatis的PageHelper 1>导入pageHelper的坐标 <dependency> <groupId>com.github.pagehel ...

  10. Windows Sublime text3 搭建Go语言环境

    第一步:Go环境和配置 1.安装 Go 开发环境(省略),假设Go安装目录为 C:\Go 2.配置环境变量,下面两个环境变脸没有就加上. 资料参考:http://studygolang.com/art ...