首页 > 如何制作一个和前端交互的div百分比示意条?

如何制作一个和前端交互的div百分比示意条?

这是我目前要做的一个东西,现在是一个纯静态的显示,但是需要做成和前端交互的一个动态的div百分比展示条。类似进度条之类的东西。我知道可以用js来做。但是不知道可不可以不用js来做,以及如果用js来做怎么和react结合在一起?

*假设我已经有了这么一个react 百分比条条的component,那么我的百分比数据可以通过this.props.xx 获得。那么请问各位大神。这个数据如何映射到CSS…… 有什么简便快捷的接解决方法么= = ?

多谢。

import React from 'react';

class PercentageBar extends React.Component {
    render() {
        return (

        );
    }
}

export default PercentageBar

==========================以上是原问题===========================

谢谢各位= = 已经解决了:方法是这样的= =

import React from 'react';

class PercentageBar extends React.Component {
    render() {
        var completed = +this.props.completed;
            if (completed < 0) {
                  completed = 0;
            };
            if (completed > 100) {
                  completed = 100;
            };

        var style = {
              backgroundColor: this.props.color || 'rgb(150,205,69)',
              width: completed + '%',
              transition: "width 200ms",
              height: this.props.height || 22
        };

        return (
            <div className="progressbar-container">
                <div className="progressbar-progress" style={style}>
                    {this.props.children}
                </div>
            </div>
        );
    }
}

export default PercentageBar

代码随意写的 没验证 请参考

HTML

<div class="progress">
    <div class="progress-bar" style="width: 0%;"></div>
</div>

Style

.progress{
    background-color: #eaeaea;
    width: 100%;
    width: 100vw;
    height: 20px;
}

.progress .progress-bar{
    background-color: #96cd45;
    -webkit-transition: .5s;
            transition: .5s;
}

.progress-bar-complete{
    width: 100%;
    color: red;
}

JS

(function($){
    
    setTimeout(function(){
        $('.progress .progress-bar').className += ' progress-bar-complete';
    }, 500);
    
})(document.querySelector.bind(document));
【热门文章】
【热门文章】