我正尝试在enyo中编写一个垂直滑块(就像调音台上的一个控件)。我试图避免从头开始,所以我开始调整onyx.Slider类。我改变了样式,从左到上,从宽到高,并进行了一些其他的调整,它是有效的。我现在坚持让滑块从下到上填充,因为在它垂直的那一分钟,它是从上到下填充的。提前感谢您的帮助。
以下是我所做的代码更改:
在ProgressBar.js中:
updateBarPosition: function(inPercent) {
this.$.bar.applyStyle("height", inPercent + "%");
},在Slider.js中(除以64是一个临时的技巧):
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%;
} 汤姆
发布于 2013-05-15 23:26:33
你可以采取几种方法。最明显的(除了我没有首先想到的事实)就是交换条和条的背景/渐变。这将使您看起来像是从底部填充。我建议你这样做。
另一种方法是我在这里的jsFiddle中所做的:http://jsfiddle.net/RoySutton/b9PmA/ (忽略加倍的updateBarPosition函数)
我没有直接修改这些文件,而是从slider派生并覆盖了相应的函数,并为垂直滑块添加了一个新类。
我改变了‘填充’的绝对位置在滑块中。
现在,您的下一个问题是值'0‘是完全填充的,而'100’是完全空的。我通过修改你的calcKnobPosition来调整最大值并反转定位逻辑来处理这个问题,如下图所示:http://jsfiddle.net/RoySutton/b9PmA/2/
return this.max - (y / this.getBounds().height) * (this.max - this.min);https://stackoverflow.com/questions/16560608
复制相似问题