Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recreating the HTML5 range input for Mobile Safari (webkit)?

So I've been working on a HTML5 iPad application for work and have come across a problem. I didn't have access to an iPad whilst first working on this app and relied on desktop Safari to get my app quickly together (probably not the best thing, anyhow...)

I'm having to rely on a input range for a part of the interface. After seeing that HTML5 had a range input, I was happy as this is just what I needed. I even managed to style it up to exactly what was designed:

HTML5 range input

This is great! ...until I actually tried it on an iPad and it doesn't work. Just shows a text input. I'm now wondering what to do... I do need a slider, something that when dragged, it spits out the data. Obviously needs to work with touch. After looking around all over the web, there doesn't seem to be a solid solution.

What do you guys suggest here? What's the proper way of coding up a working touch-friendly slider, just like the native HTML5 one that it doesn't support!?

Any ideas/thoughts/knowledge/experience would be greatly appreciated! James

like image 338
littlejim84 Avatar asked Mar 30 '11 09:03

littlejim84


People also ask

How do you type a range input in HTML?

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.

How do you increase range in HTML?

You can`t change the length/size of the HTML5 range input without using CSS. the only attributes you can use are value, min, max and step. And none of those do what you need.

How do I change the color of my slider range?

If the general appearance of the slider is fine, but the default blue color (in Chrome) needs to fit a theme color, apply a filter: hue-rotate(); to the input[type="range"] element. Other filters can be used. Some even change the background color of the slider. Save this answer.


2 Answers

I tested all the proposed "solutions" and found them all lacking.
All are excessively bloated, some change your existing markup or force unnecessary CSS styles.

So I crafted my own solution in 2kb of JavaScript (minified).

Screenshot on iOS Device
Try it (on your mobile device): https://range-touch.herokuapp.com

Code: https://github.com/dwyl/range-touch (concise and commented)

To get this working in your own project all you need to do is include the
range-touch.min.js file in your page/template.

Magically <input type="range"> works on all mobile devices.

You can style the slider & button how ever you like.
I've included sample styles in the optional/style.css

Note: this solution Assumes you have JQuery or Zepto.js

like image 136
nelsonic Avatar answered Oct 07 '22 23:10

nelsonic


You could have a look over http://jqueryui.com/demos/slider/ . Try accessing the page on the iPad and see if it's touch friendly.

like image 39
Cristian Necula Avatar answered Oct 08 '22 00:10

Cristian Necula