【发布时间】:2016-01-29 16:53:30
【问题描述】:
我试图在我的 Rails 应用程序中使用ProgressBar.js,但我承认我不太了解 Javascript。我的一个观点中有这段代码:
<div class="circleprogress" id="circleprogress"></div>
<script type="text/javascript">
window.onload = function onLoad() {
var circle = new ProgressBar.Circle('#circleprogress', {
color: '#38A6A6',
duration: 3000,
easing: 'easeInOut',
strokeWidth: 7,
trailColor: '#D5D5D5',
trailWidth: 1,
text: {
value: <%= (@percentage_of_goal * 100).round %> + '%'
},
});
circle.animate(<%= @percentage_of_goal%>);
};
</script>
@percentage_of_goal 已经在我的控制器中定义了。代码工作正常,但只有在我刷新页面之后。
我看过other questions 似乎有同样的问题,但解决方案是安装jquery-turbolinks gem,我已经这样做了,并且在我的 application.js 中需要它,它仍然仅在重新加载后有效。
我该如何解决这个问题?
【问题讨论】:
-
如果将 window.onload 更改为 window.ready 会怎样?
标签: javascript jquery ruby-on-rails