React-FlipOver-Counter(日历翻页)

跟窝一起学习鸭~~
//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(日历翻页)的更多相关文章
- jq数字翻页效果,随机数字显示,实现上下翻动效果
最近在做一个项目,需要实时展示一串数字,要有类似于日历翻页的效果,在网上找寻了一番,发现dataStatistics这个插件http://www.jq22.com/jquery-info8141能实现 ...
- vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件
vue10行代码实现上拉翻页加载更多数据,纯手写js实现下拉刷新上拉翻页不引用任何第三方插件/库 一提到移动端的下拉刷新上拉翻页,你可能就会想到iScroll插件,没错iScroll是一个高性能,资源 ...
- webapp应用--模拟电子书翻页效果
前言: 现在移动互联网发展火热,手机上网的用户越来越多,甚至大有超过pc访问的趋势.所以,用web程序做出仿原生效果的移动应用,也变得越来越流行了.这种程序也就是我们常说的单页应用程序,它也有一个英文 ...
- jquery css3问卷答题卡翻页动画效果
这个选项调查的特效以选项卡的形式,每答完一道题目自动切换到下一条,颇具特色.使用jQuery和CSS3,适合HTML5浏览器. 效果展示 http://hovertree.com/texiao/jqu ...
- 采用cocos2d-x lua 的listview 实现pageview的翻页效果之上下翻页效果
--翻页滚动效果local function fnScrollViewScrolling( sender,eventType) -- body if eventType == 10 the ...
- HTML5翻页电子书
体验效果:http://hovertree.com/texiao/jquery/60/ 图片请用正方形的 参考:http://hovertree.com/h/bjaf/d339euw9.htmhttp ...
- [原创]纯CSS3打造的3D翻页翻转特效
刚接触CSS3动画,心血来潮实现了一个心目中自己设计的翻页效果的3D动画,页面纯CSS3,目前只能在Chrome中玩,理论上可以支持Safari. 1. 新建HTML,代码如下(数据和翻页后的数据都是 ...
- Web jquery表格组件 JQGrid 的使用 - 5.Pager翻页、搜索、格式化、自定义按钮
系列索引 Web jquery表格组件 JQGrid 的使用 - 从入门到精通 开篇及索引 Web jquery表格组件 JQGrid 的使用 - 4.JQGrid参数.ColModel API.事件 ...
- css实现翻页效果
如图,鼠标移动到图上,实现右上角翻页的效果,本例主要border边框的设置. 一.基本概念 <html> <head> <style> #demo{ width:0 ...
随机推荐
- Android根据联系人姓名首字符顺序读取通讯录
Android根据联系人姓名首字符顺序读取通讯录 版权声明:本文为Zhang Phil原创文章,欢迎转载!转载请注明出处:http://blog.csdn.net/zhangphil 本文给出了A ...
- RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景?
RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? RxJS/Cycle.js 与 React/Vue 相比更适用于什么样的应用场景? - 知乎 https://www ...
- [转载] OpenCV2.4.3 CheatSheet学习(四)
五.数据的输入和输出 1. 将数据写入YAML(或XML) 注意,在OpenCV中,无论读写,文件的格式均由指定的后缀名确定.示例: FileStorage fs("test.yml&quo ...
- 提高scrapy的抓取效率
增加并发 默认scrapy开启的并发线程的个数是32个,可以适当的进行增加.在settings中进行设置CONCURRENT_REQUESTS=100 降低日志级别 在运行的时候,会有大量的日志信息的 ...
- Java程序员面试题收集(6)
<!————————————————————————————基础题122道,代码题19道————————————————————————————> JAVA相关基础知识1.面向对象的特征有 ...
- UVA11021 Tribbles
题目大意:n个麻球,第一天有k个,麻球生命期为一天,临近死亡前会有i的几率生出Pi个麻球.问m天后麻球全部死亡概率 设f[i]表示i天后一个麻球全部死亡的概率 有f[1] = P0 f[i] = P0 ...
- Leetcode86. Partition List分隔链表(双指针)
给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = 1->4-&g ...
- wsgi Python的WEB框架
Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块. pip install bottle easy_i ...
- Web App开发注意事项
1.首先我们来看看webkit内核中的一些私有的meta标签,这些meta标签在开发webapp时起到非常重要的作用 <meta content=”width=device-width, ini ...
- tomcat9 gzip
我认为apr模式比较屌所以 <Connector port=" protocol="org.apache.coyote.http11.Http11AprProtocol&qu ...