【问题标题】:Dashing: Number widget background colorDashing:数字小部件背景颜色
【发布时间】:2016-07-21 17:36:28
【问题描述】:

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

例如 我想显示每个团队成员的当前分数,每个团队成员一个小部件,带有一个向上/向下箭头,将当前分数与最后一个分数进行比较,如果分数上升,小部件背景为绿色,如果它下降,小部件背景为红色。

我的 .rb 文件从 excel 文件中传递数据。

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

就好像循环在第一次`pass后停止检测背景应该是哪种颜色。

错误或错误代码? number4.coffee

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

//
// ----------------------------------------------------------------------------
// 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;
}

}

【问题讨论】:

  • 所有缩进都丢失了,这对 CoffeeScript 尤其不利。

标签: css background coffeescript widget dashing


【解决方案1】:

您可以在单个仪表板上多次使用一个小部件,但听起来您已经拥有该部分。

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

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()
    

希望这会有所帮助。

【讨论】:

  • 感谢您的回复。我添加/替换了您的代码,每个小部件的背景都在触发“黑色”。有什么想法吗?
  • 您也可以发布这份工作吗?
猜你喜欢
  • 1970-01-01
  • 2014-12-18
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-01
  • 1970-01-01
相关资源
最近更新 更多