倒数10分钟

时间:2019-02-17 09:32:45

标签: reactjs countdown

我有一个问题,我想用这种风格用10分钟创建一个倒计时,我该怎么写

https://codepen.io/Libor_G/pen/JyJzjb

我写这个

CountCount类扩展了组件{

constructor(props) {
    super(props);
    this.state = {
        minutes: 0,
        minutesShuffle: true,
        seconds: 0,
        secondsShuffle: true
    };
}

componentDidMount() {
    this.timerID = setInterval(
        () => this.updateTime(),
        1000
    );
}

componentWillUnmount() {
    clearInterval(this.timerID);
}

updateTime() {
    const time = new Date;
    const total = Date.parse(9000) - Date.now()
   const minutes = time.getMinutes();
    const seconds = Math.floor((total / 1000) % 60);
    if (minutes !== this.state.minutes) {
        const minutesShuffle = !this.state.minutesShuffle;
        this.setState({
            minutes,
            minutesShuffle
        });
    }
    // on second chanage, update seconds and shuffle state
    if (seconds !== this.state.seconds) {
        const secondsShuffle = !this.state.secondsShuffle;
        this.setState({
            seconds,
            secondsShuffle
        });
    }
}    

请帮助我!

0 个答案:

没有答案