简体   繁体   English

如何使输入类型=“范围”触发溢出滚动?

[英]How to make input type=“range” trigger an overflow scroll?

I have an input type="range" that is bigger then its parent. 我有一个输入type =“ range”,它大于其父级。 I want to make it scroll when the slider-thumb exits the parent width. 我想让它在滚动滑块退出父级宽度时滚动。

Here is an example, when you exceed the parent width there should be a scroll. 这是一个示例,当您超过父级宽度时,应该有一个滚动条。 How can I do that? 我怎样才能做到这一点?

http://jsbin.com/ikemo4/edit http://jsbin.com/ikemo4/edit

Please note that input type="range" will only work in WebKit browsers. 请注意,输入type =“ range”仅在WebKit浏览器中有效。

The very simple option is to use the oninput event and, assuming your values and widths are accurately represented by the fiddle, when the value of the range increases past the width of the container manipulate the scrollLeft by rangeValue - parentWidth . 一个非常简单的选项是使用oninput事件,并假设您的值和宽度由小提琴准确地表示,当范围的值增加到超过容器的宽度时,可以通过rangeValue-parentWidth来操纵scrollLeft I achieved this in your jsBin example using the following code: 我使用以下代码在您的jsBin示例中实现了这一点:

var rng = document.getElementById("range");

rng.oninput = function () {
    this.parentNode.scrollLeft = this.value - 400;
}

And the result can be demoed here . 结果可以在这里演示。 You might want to tweak it slightly to get the desired affect. 您可能需要稍作调整以获得所需的效果。

Another option would be to check if the value is greater than a certain amount and scroll the box fully to the right. 另一个选择是检查该值是否大于某个值,然后将框完全向右滚动。 When it goes back the other way, scroll fully to the left. 当它向后退时,请向左完全滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM