简体   繁体   English

Rails,JS,CSS-无法获得过渡效果

[英]Rails, JS, CSS - can't get transition effect working

I have bar charts in my application that work fine but i'd like them to transition left to right on load across the screen. 我的应用程序中有条形图,可以很好地工作,但是我希望它们在整个屏幕上加载时从左向右过渡。 So I have tried the following: 所以我尝试了以下方法:

CSS: CSS:

.progress-meter-interest{
  background-color: #FFD733;
  width: 250px;
}

.progress-meter-interest.horizTranslate {
  animation-direction:normal;
  -webkit-transition: 3s;
  -moz-transition: 3s;
  -ms-transition: 3s;
  -o-transition: 3s;
  transition: 3s;
}

In view: 鉴于:

<div class="progress-meter-interest horizTranslate" style ="width: <%= homework.average_interest * 100 / 5 %>%"><%= homework.average_interest %></div>

JS: JS:

<script>
$(document).ready(function() {
  $( ".progress-meter-interest" ).each(function() {
    var length = $( this ).data("bar-length");
    $( this ).css('width', length);
  });
});
</script>

Clearly I am not defining data-bar-length as a set value in the div as the graphs are dynamic. 显然,由于图形是动态的,因此我没有将div的数据条长度定义为设置值。 When I do define it the transition effect works. 当我定义它时,过渡效果就起作用了。

How do I get it to work with the dynamic data? 如何使它与动态数据一起使用?

Thanks. 谢谢。 Appreciate any help. 感谢任何帮助。

The transition shorthand property needs to know which property to transition. transition简写属性需要知道要过渡的属性。 At the very least you will need to change transition: 3s to transition: width 3s so your CSS should look like: 至少您将需要将transition: 3s更改为transition: width 3s因此您的CSS应该如下所示:

.progress-meter-interest{
  background-color: #FFD733;
  width: 250px;
}

.progress-meter-interest.horizTranslate {
  animation-direction:normal;
  -webkit-transition: width 3s;
  -moz-transition: width 3s;
  -ms-transition: width 3s;
  -o-transition: width 3s;
  transition: width 3s;
}

See https://developer.mozilla.org/en-US/docs/Web/CSS/transition for more details on the transition property. 有关transition属性的更多详细信息,请参见https://developer.mozilla.org/en-US/docs/Web/CSS/transition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM