element. Usage: Include range.js " /> element. Usage: Include range.js " /> element. Usage: Include range.js "/>

JavaScript library to resize, reduce, or change ranges of DOM elements.

Overview

Range.js

JavaScript library to resize, reduce, or change ranges of DOM elements using the HTML5 <input type="range"> element.

Usage:

  1. Include range.js in your dependencies
  2. Wrap sections that you want to have input range control over
  3. 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>
  1. 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.

Examples

Here are live examples.

  1. 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>
  1. 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>
  1. Image example:
<!-- image example -->
<section data-range="true">
     <input type="range">
     <img src="ok.png" width="250">
</section>

API

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>

Contributing

This is a small, open-source project - contributions are welcomed! Check the Issues section to view open issues, and future goals.

  1. Fork the repository
  2. Create a branch for your patch or feature
  3. Make your changes
  4. Push to your Fork
  5. Open a pull request and describe your changes

Acknowledgements

Thank you to the following individuals for help and contributions:

  • Noah Freitas
  • James Quinlan
You might also like...

↕️ A little Alpine.js plugin to automatically resize a textarea to fit its content.

↕️ Alpine Autosize ↕️ A little Alpine.js plugin to automatically resize a textarea to fit its content. 🚀 Installation CDN Include the following scri

Nov 5, 2022

Custom Vitest matchers to test the state of the DOM, forked from jest-dom.

vitest-dom Custom Vitest matchers to test the state of the DOM This library is a fork of @testing-library/jest-dom. It shares that library's implement

Dec 16, 2022

LiveJSON provides LiveView-like updating for JSON objects rather than DOM elements.

live_json LiveJSON provides LiveView-like updating for JSON objects rather than DOM elements. It works within your existing LiveViews - just use push_

Dec 29, 2022

📃 Fold up DOM elements like paper

📃 Fold up DOM elements like paper

OriDomi Fold up DOM elements like paper Dan Motzenbecker, MIT License @dcmotz Visit oridomi.com for examples, documentation and notes. Read the annota

Dec 14, 2022

jQuery-plugin for add/remove dom-items with renaming form-elements (arrays)

dynamicrows jQuery-plugin for add/remove rows by cloning existing row / renaming form-elements (arrays). Requirements jQuery =2.0 if move-action used

Nov 9, 2020

Add class(es) to DOM elements while waiting for async action. Promise or callback.

jquery.loading Add class(es) to DOM elements while waiting for async action. Promise or callback. Install The simplest way is to include loading.js in

Mar 26, 2022

A lightweight function that executes callback when we see specific DOM elements.

did-i-see A lightweight function that executes callback when we see specific DOM elements. Built with IntersectionObserver. 🔴 Demo: https://did-i-see

Oct 18, 2022

Minimal versions of popular analytics libraries. Reduce the impact of third-party scripts on your application.

minimal-analytics This project aims to provide minimal implementations of popular analytics libraries. It's aimed at users who want to reduce the impa

Dec 25, 2022

why make apps to increase focus -- when you can make apps to reduce focus

impossifocus 🕺 What is this? ImpossiFocus will measure focus by reading your brainwaves -- and if you're in the zone, it'll ensure that changes with

Nov 30, 2022
Comments
  • List Manipulation unable to handle double-nested elements

    List Manipulation unable to handle double-nested elements

    While range.js can be used to control the display of lists and nested lists, it fails to cover any deeper level of nested elements. I somewhat expected this, so I will outline a potential fix, assuming I am correct in my assumption of what the issue is.

    Theory: In updateList() I am not recursively exploring this target element, rather I am using hardcoded for loops to search, at most, two layers of the element.

    Potential Fix: Write a recursive method similar to searchChildren() that will check for child elements, else it will compare the elements data-position to the current range to dictate it's display property. This will prevent placing a limit in the maximum number of nested elements able to be selectively hidden by the associated range input.

    bug 
    opened by jcquinlan 1
  • Add nested LI support

    Add nested LI support

    So I built in support for nested lists. I use a custom attribute that keeps track of the objective position of each non-UL element within the main UL. This attribute is added during a recursive search of the main UL element in a method called searchChildren().

    I also changed updateList() to no longer change the display of any UL element, since that hides all the nested LI elements prematurely. Instead, I compare each LI elements data-position to the current range of the input, and your code will then selectively hide the elements with a higher data-position.

    Let me know what you think of the documentation, I can add more if you need. I also think I renamed a few arguments that were accepting event objects but being called "el". This is slightly confusing, so I changed them to "e" for "event".

    opened by jcquinlan 1
  • Quickly changing range value on multiple text elements

    Quickly changing range value on multiple text elements

    Issue:

    There is a known bug when using the text range on p elements that have various lengths.

    For example, p1 has 150 characters, p2 has 50 characters, and p3 has 10 characters. Using the range slider on elements in this context is buggy and causes some text within p elements to not show/hide correctly.


    How to view issue:

    Simply change the amount of text within various p elements, and use the input slider. Try moving the slider quickly, and slowly to view the text differences.


    Possible solutions:

    The algorithm in updateInnerText() is not performing quick enough when the range is changed (lines 93-109).

    // if less than last paragraph, cut and break
    if (cut < paragraphs[numParagraphs - 1]['length']) {
        target.parentNode.children[numParagraphs].innerHTML = paragraphs[numParagraphs - 1]['text'].substring(0, paragraphs[numParagraphs - 1]['length'] - cut);
    }
    // otherwise backwards loop to remove text in each p
    else {
        for (var x = numParagraphs; x > 0; x--) {
            // if less than current p, cut and break
            if (cut < paragraphs[numParagraphs - 1]['length']) {
                target.parentNode.children[x].innerHTML = paragraphs[x - 1]['text'].substring(0, paragraphs[x - 1]['length'] - cut);
                break;
            }
            else {
                // remove this p
                target.parentNode.children[x].innerHTML = paragraphs[x - 1]['text'].substring(0, 0);
                // subtract this p length from cut total
                cut = cut - paragraphs[x - 1]['length'];
            }
        }
    }
    
    bug 
    opened by kylebelanger 0
  • The project needs a roadmap

    The project needs a roadmap

    Do you have a direction you'd like to take the project? In what types of situations do you see the library being used? Are there any features you envision being added?

    enhancement 
    opened by jcquinlan 3
curtains.js is a lightweight vanilla WebGL javascript library that turns HTML DOM elements into interactive textured planes.

What is it ? Shaders are the new front-end web developpment big thing, with the ability to create very powerful 3D interactions and animations. A lot

Martin Laxenaire 1.4k Jan 1, 2023
A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mechanism to manipulate DOM elements

JavaScript Project to Manipulate DOM Elements DFlex A Drag-and-Drop library for all JavaScript frameworks implementing an enhanced transformation mech

DFlex 1.5k Jan 8, 2023
A super tiny Javascript library to make DOM elements draggable and movable. ~500 bytes and no dependencies.

dragmove.js A super tiny Javascript library to make DOM elements draggable and movable. Has touch screen support. Zero dependencies and 500 bytes Gzip

Kailash Nadh 814 Dec 29, 2022
🖱 A JavaScript library for interactively picking DOM elements

pick-dom-element A JavaScript library (written in TypeScript) for interactively picking DOM elements. Usage Create an instance of the ElementPicker cl

Harry Marr 23 Dec 4, 2022
An extension of DOM-testing-library to provide hooks into the shadow dom

Why? Currently, DOM-testing-library does not support checking shadow roots for elements. This can be troublesome when you're looking for something wit

Konnor Rogers 28 Dec 13, 2022
An open-source Typing-effect Library, That enables potential users to add a typing effect to mere DOM Elements.

Typing Effect Library An open-source Typing-effect Library I created. That enables potential users to add a typing effect to mere DOM Elements. Tool P

Okoye Charles 14 Oct 3, 2022
Tiny js library to make DOM elements movable and resizable .

resizedrag.js Tiny js library to make DOM elements movable and resizable . Demo Here . This library has added resizing functionalities to the existing

null 4 Mar 28, 2022
A pure javascript class for paginating through any number of DOM elements

PurePajinate A pure javascript class for paginating through any number of DOM elements. Inspired by Pajinate, a plugin for jQuery. Options Option Type

Olivier Buisard 3 Nov 21, 2022
Dynamically resize, format and optimize images based on url modifiers.

Local Image Sharp Dynamically resize, format and optimize images based on url modifiers. Table of Contents ✨ Features ?? Installation ?? Usage Contrib

Strapi Community 30 Nov 29, 2022
logseq custom.js and custom.css utilities : resize query table columns, hide namespaces...

logseq-custom-files custom.js and custom.css utilities for Logseq. current version v20220331 query table view : add handles on the query table headers

null 44 Dec 7, 2022