JavaScript library to resize, reduce, or change ranges of DOM elements using the HTML5 <input type="range">
element.
- Include range.js in your dependencies
- Wrap sections that you want to have input range control over
- Add a
data-range="true"
attribute to the wrapper element
<section data-range="true">
<input type="range">
<p>This is some sample text that you can reduce.</p>
</section>
- Initialize a Range object within the page
<script>
range = new Range();
</script>
You can have multiple sections with data-range="true"
attributes attached on the same page. The library will automatically detect the type of content within each section.
Here are live examples.
- Text example:
<!-- text example -->
<section data-range="true">
<input type="range">
<p>This is some sample text that you can reduce.</p>
<p>Also works with multiple p elements within the wrapper.</p>
</section>
- List example:
<!-- list example -->
<section data-range="true">
<input type="range">
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
<ul>
<li>three-one</li>
<li>three-two</li>
</ul>
<li>Item four</li>
</ul>
</section>
- Image example:
<!-- image example -->
<section data-range="true">
<input type="range">
<img src="ok.png" width="250">
</section>
You can set the step
of the range through object initialization. The default step
is 1. However, setting a decimal can help make scrolling on the input element smoother for items that have a small amount of content (i.e. text or lists).
To set the step
, pass an integer or decimal on object initialization.
<script>
// set step with .25
range = new Range(0.25);
</script>
This is a small, open-source project - contributions are welcomed! Check the Issues section to view open issues, and future goals.
- Fork the repository
- Create a branch for your patch or feature
- Make your changes
- Push to your Fork
- Open a pull request and describe your changes
Thank you to the following individuals for help and contributions:
- Noah Freitas
- James Quinlan