Open gupta-ankit opened 9 years ago
Yes, it is (basically your syntax, maybe naming the variable "slider" is an issue?). This works for me:
var mySlider = d3.slider()
.min(0)
.max(10)
.value(7)
.on("slide", function(evt, value) {
doSomething(value)
});
d3.select("#div-where-the-slider-will-be-attached-to")
.call(mySlider);
mySlider.value(newValue);
Do you work with the latest version of the slider? This functionality became available on 29 Sep 2014 through https://github.com/turban/d3.slider/commit/bb33d878b627d4c20c13212b75fd50d1ca1abcad
I experienced also a problem with the getter/setter function for the value.
When the value is not changed at creation (as in the example above), or when the value is set to 0, the setter doesn't work.
The problem (I think) in the code below is that the condition if (value) {
will return false if the value is zero.
slider.value = function(_) {
if (!arguments.length) return value;
if (value) {
moveHandle(stepValue(_));
};
value = _;
return slider;
};
Therefore I would suggest to use another condition like:
if (typeof value !== 'undefined') {
or
if (value>=0) {
Regards. Nice plugin by the way.
man thank the lord i found this @VD17593 thanks for the spot.. confirmed same behavior for me trying to set a value to something other than zero... new to JS so a rude way to find out that 0 == false
Currently I can create a slider like this
This creates a slider. Is there a way to update the position of the slider via javascript. For example, executing
slider.value(5)
should update the position of the slider.