首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dashing:数字小工具背景颜色

Dashing:数字小工具背景颜色
EN

Stack Overflow用户
提问于 2016-04-02 03:25:09
回答 1查看 577关注 0票数 0

数字小部件是否可以在同一仪表板上多次使用?

例如,我想要显示每个团队成员的当前分数,每个团队成员一个小工具,用向上/向下箭头比较当前分数和最后一个分数,如果分数是向上的,则小工具背景是绿色的,如果是向下的,则小工具背景是红色的。

我的.rb文件传递来自excel文件的数据。

每个小部件都显示正确的当前分数,每个小部件都显示正确的向上/向下箭头,所有小部件都显示与我想要的颜色相同但相反的颜色,尽管.coffee显示的颜色相反。

就像检测背景应该是哪种颜色的循环在第一次“通过”之后停止一样。

错误还是糟糕的代码?number4.coffee

代码语言:javascript
复制
class Dashing.Number4 extends Dashing.Widget

@accessor 'current', Dashing.AnimatedValue

@accessor 'difference', ->
if @get('last')
last = parseInt(@get('last'))
current = parseInt(@get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""

@accessor 'arrow', ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then 'fa fa-arrow-up' else 'fa fa-arrow-down'

constructor: ->
super

@onData(Dashing.lastEvents[@id]) if Dashing.lastEvents[@id]
onData: (data) ->
if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).css('background-color', '#006600') else $(@node).css('background-color', '#660000')

number4.scss

代码语言:javascript
复制
//
// ----------------------------------------------------------------------------
// Mixins
// ----------------------------------------------------------------------------
@mixin transition($transition-property, $transition-time, $method) {
-webkit-transition: $transition-property $transition-time $method;
-moz-transition: $transition-property $transition-time $method;
-o-transition: $transition-property $transition-time $method;
transition: $transition-property $transition-time $method;
}

// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$value-color: #fff;

$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.7);

// ----------------------------------------------------------------------------
// Widget-number styles
// ----------------------------------------------------------------------------
.widget-number4 {

.title {
color: $title-color;
font-size: 40px;

 }

.value {
color: $value-color;

}

.change-rate {
font-weight: 500;
font-size: 30px;
color: $value-color;
}

.more-info {
color: $moreinfo-color;
font-size: 23px;
bottom: 40px;

}

.updated-at {
color: white;
font-size: 23px;
}

}
EN

回答 1

Stack Overflow用户

发布于 2016-04-04 12:29:43

您可以在单个仪表板上多次使用一个小部件,但听起来您已经让这部分工作了。

您需要淡出小部件,设置背景色,然后再次淡入。否则,您将看不到背景颜色更改,因为渲染已经发生。

代码语言:javascript
复制
onData: (data) ->
      
    if @get('last')
      if parseInt(@get('current')) > parseInt(@get('last')) then $(@node).fadeOut().css('background-color', "#006600").fadeIn() else $(@node).fadeOut().css('background-color', "#660000").fadeIn()

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36364349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档