Question

I am trying to code a vertical slider in enyo (Like a control on mixing desk). I was trying to avoid starting from scratch so I started tweaking the onyx.Slider class. I changed to styles from left to top and from width to height and with a few other tweaks, it's working. I'm now stuck on getting the slider to fill from bottom to top as at the minute it is vertical but it fills from the top down. Thanks in advance for any help.

Here are the code changes I have done:

in ProgressBar.js:

updateBarPosition: function(inPercent) {
    this.$.bar.applyStyle("height", inPercent + "%");
},

in Slider.js (dividing by 64 is a temporary hack):

valueChanged: function() {
    this.value = this.clampValue(this.min, this.max, this.value);
    var p = this.calcPercent(this.value);
    this.updateKnobPosition(p/64);
    if (this.lockBar) {
        this.setProgress(this.value);
    }
},
updateKnobPosition: function(inPercent) {
    this.$.knob.applyStyle("top", inPercent + "%");
},
calcKnobPosition: function(inEvent) {
    var y = inEvent.clientY - this.hasNode().getBoundingClientRect().top;
    return (y / this.getBounds().height) * (this.max - this.min) + this.min;
},

CSS:

/* ProgressBar.css */
.onyx-progress-bar {
  margin: 8px;
  height: 400px;
  width: 8px;
  border: 1px solid rgba(15, 15, 15, 0.2);
  border-radius: 3px;
  background: #b8b8b8 url(./../images/gradient-invert.png) repeat-x;
  background-size: auto 100%;
}
.onyx-progress-bar-bar {
  height: 100%;
  border-radius: 3px;
  background: #58abef url(./../images/gradient.png) repeat-x;
  background-size: auto 100%;
} 

Tom

Was it helpful?

Solution

There are a couple of approaches you could take. The most obvious (except for the fact it didn't occur to me first) is just to swap the background/gradient of the bar and the bar-bar. This will give you the appearance of filling from the bottom. I would recommend this.

The other method is what I did in this jsFiddle here: http://jsfiddle.net/RoySutton/b9PmA/ (Do ignore the doubled updateBarPosition function)

Instead of modifying those files directly, I derived from Slider and overrode the appropriate functions and added a new class for the vertical slider.

I changed the 'fill' to be absolutely positioned within the slider.

Now, your next problem is that value '0' is fully filled and '100' is fully empty. I handled that by modifying your calcKnobPosition to adjust from max and inverting the positioning logic as seen in this fiddle here: http://jsfiddle.net/RoySutton/b9PmA/2/

return this.max - (y / this.getBounds().height) * (this.max - this.min);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top