Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make html5 input[type=range] with many steps snap to the middle [closed]

I have an <input type=range> with 60000 steps. I need the caret to jump to the middle when it is moved close to the middle. How can I do that?

I am using the Angular and jQuery libraries.

like image 271
Fyodor Khruschov Avatar asked Jan 20 '15 23:01

Fyodor Khruschov


People also ask

How do I limit input range in html?

The max attribute specifies the maximum value for an <input> element. Tip: Use the max attribute together with the min attribute to create a range of legal values. Note: The max and min attributes works with the following input types: number, range, date, datetime-local, month, time and week.

How do I create a vertical range slider in html?

For Chrome, use -webkit-appearance: slider-vertical . For IE, use writing-mode: bt-lr . For Firefox, add an orient="vertical" attribute to the html. Pity that they did it this way.

Which input type creates a range slider?

The <input type="range"> defines a control for entering a number whose exact value is not important (like a slider control).

How do you style input type range?

To style the range input with CSS you'll need to apply styles to two pseudo-elements: ::-webkit-slider-thumb and ::-webkit-slider-runnable-track . Find out how you can apply custom styling and make the range input more functional and appealing. Contents of the article: CSS selectors for the range input.


1 Answers

There is a HTML5 feature that provides detent-snapping natively, using the list attribute and matching datalist element. Each element in the list becomes a detent point in the slider, with a tick-mark as well as snapping.

<input type="range" value="0" min="0" max="60000" step="1" list="my-detents">

<datalist id="my-detents">
  <option value="30000">
</datalist>

The datalist element can be placed anywhere in the HTML; it’s just defining the list (here named my-detents) for use by the input element.

According to MDN and caniuse.com, as of February 2019, use of datalist with range inputs is supported by Chrome, IE, Edge, and preview versions of Safari. (Firefox supports datalist for text inputs only.)

like image 102
Kevin Reid Avatar answered Sep 28 '22 05:09

Kevin Reid