admin管理员组文章数量:1335624
i am trying to change the background color of div on change function of paper slider with slider's current value but failed to get value of slider i have tried on-immediate-value-change or on-change function ,but i don't know how to get current value of paper-slider
i am trying to change the background color of div on change function of paper slider with slider's current value but failed to get value of slider i have tried on-immediate-value-change or on-change function ,but i don't know how to get current value of paper-slider
Share Improve this question asked Feb 26, 2015 at 6:38 Tushar PurohitTushar Purohit 931 silver badge11 bronze badges3 Answers
Reset to default 7Well, according to the documentation, there are two different kinds of value for the paper-slider
:
value
The number that represents the current value.immediateValue
The immediate value of the slider. This value is updated while the user is dragging the slider.
One can access these properties directly on the paper-slider
element.
While the user drags the slider, a first event is fired continuously: immediate-value-change
.
When the user stops dragging the slider, two other events are fired: change
and value-change
. The difference between the two is that the change
event is only fired on user's interaction.
Considering these informations, you may add to your host element the following snippets (your slider should have a slider
id, but you can obviously change that):
listeners: {
'immediate-value-change': 'immediateValueChangeHandler',
'change': 'changeHandler'
},
immediateValueChangeHandler: function (e) {
var value = this.$.slider.immediateValue;
// do something
},
changeHandler: function (e) {
var value = this.$.slider.value;
// do something
}
easiest way i know of to get the value of a slider is to assign it a declarative variable and use that in your javascript.
example
<paper-slider min="0" max="100" value="{{sliderValue}}" on-change="{{sliderChange}}"></paper-slider>
then in js
sliderChange: function () {
var value = this.sliderValue;
// do something with value
}
plunker example http://plnkr.co/edit/gihpf5aZH4obhquaDtZQ?p=preview
edit: original post using event sender value returned the value of the beginning of the event and not the end value
I would suggest listening to the change event and then accessing the srcElement.value to get the current value
sliderElement.addEventListener('change', function(e) {
console.log(e.type, e.srcElement.value);
});
本文标签:
版权声明:本文标题:javascript - How to get immediate value current value of paper-slider on change event or immediate value change event - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742312396a2451134.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论