【发布时间】:2015-11-30 12:06:13
【问题描述】:
当我尝试将“progressbar.js”包装在聚合物元素中时,我无法访问 circleprop。
var startColor = '#FC5B3F';
var endColor = '#6FD57F';
Polymer({
is: "home-view",
properties: {
value: {
type: String,
observer: '_valueChanged'
},
circleProp: {
type: Object,
notify: true,
reflectToAttribute: true
}
},
ready: function() {
var element = this.$$('#circleValue');
this.circleProp = new ProgressBar.Circle(element, {
color: startColor,
trailColor: '#eee',
trailWidth: 1,
duration: 2000,
easing: 'easeInOut',
strokeWidth: 5,
text: {
value: '0'
},
// Set default step function for all animate calls
step: function(state, circle) {
circle.path.setAttribute('stroke', state.color);
circle.setText((circle.value() * 100).toFixed(0));
}
});
this.circleProp.animate(0.3, {
from: {color: startColor},
to: {color: endColor}
});
},
attach : function() {
if (this.circleProp) {
this.circleProp.animate(this.value, {
from: {color: startColor},
to: {color: endColor}
});
}
},
_valueChanged : function(oldValue, newValue) {
if (this.circleProp) {
this.circleProp.animate(newValue, {
from: {color: startColor},
to: {color: endColor}
});
}
}
});
如何访问 circleProp 以便制作动画。或者如何访问 _valueChanged 中的对象?只能访问该元素的 DOM。
【问题讨论】:
-
你应该可以使用
this关键字访问,结帐this out。 -
_valueChanged 可能在准备好之前运行,Polymer 很奇怪。尝试从控制台手动运行它并在其中放置一个 console.log(this.circleProp) 以查看发生了什么
标签: javascript polymer polymer-1.0