How to dynamically change the steps of a dragdealer (slider) instance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to dynamically change the steps of a dragdealer (slider) instance

    As a Web Developer, time and again you come across problems that seem like a roadblock to what you are trying to accomplish. I've had my fair share. Having found the fantastic Dragdealer library that allows me to create fancy mouse- and touch-friendly sliders, I stumbled upon a problem trying to figure out how I could dynamically change the steps of an already-instantiated slider.

    I was dreading the thought of having to create a separate HTML element for the slider that has fewer steps than the other - surely there is a way to change the steps of a slider and make Dragdealer recalculate it all like it does on initialisation?

    Turns out, there is:

    Code:
    var slider = new Dragdealer( ... );
    
    slider.options.steps = 2; // sets the attribute value
    
    slider.stepRatios = slider.calculateStepRatios(); // calculates step ratios based on attribute value
    Hope this helps.
Working...
X