跟窝一起学习鸭~~

//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. dubbo入门学习(四)-----dubbo配置

    配置来源 首先,从Dubbo支持的配置来源说起,默认有四种配置来源: JVM System Properties,-D参数 Externalized Configuration,外部化配置 Servi ...

  2. PAT甲级——A1057 Stack

    Stack is one of the most fundamental data structures, which is based on the principle of Last In Fir ...

  3. python函数当容器

    def func(): pass func2 = func func2() i = [func,func2] for a in i: a() 函数名就是内存地址,加()代表执行

  4. 从大数据到快数据 数据智创未来——2019 CCF大数据与计算智能大赛正式开赛!

    8月17日,以“数据驱动,智创未来”为主题的2019 CCF大数据与计算智能大赛(CCF Computing Intelligence Contest,简称CCF BDCI)全球启动仪式,在北京大学正 ...

  5. Hackerrank--Team Formation

    题目链接 For an upcoming programming contest, Roy is forming some teams from the n students of his unive ...

  6. java多线程三种方式

    java多线程都有几种方式 有三种: (1)继承Thread类,重写run函数 创建: class xx extends Thread{ public void run(){ Thread.sleep ...

  7. [jnhs]id字段修改错误导致hibernate hql查询整表只返回第一条数据

    调试发现,查询到的就是一条数据 hql语句执行结果 Hibernate: select ballmodel0_.ball_id as ball_id1_1_, ballmodel0_.color as ...

  8. 关于java中的异常

    java中有时候要写形如下图中的方法抛出异常 之所以要这么写(要在方法声明行写上throws ...)是因为这种 FileNotFoundException 属于编译异常 不属于运行时异常 不会主动抛 ...

  9. JSP-request(httpServletRequest)

    HttpServletRequest 1 HttpServletRequest概述 2 request运行流程 3 通过抓包工具抓的http请求 4 请求行信息的相关方法 //1.获得请求方式 Str ...

  10. Nginx 扫盲

    layout: post title: Nginx-扫盲 category: Nginx tags: [代理] Nginx 基本安装和配置文件讲解 简介 轻量级web服务器.反向代理服务 负载均衡策略 ...