All Projects → Amphiluke → handy-scroll

Amphiluke / handy-scroll

Licence: MIT license
Handy dependency-free floating scrollbar widget

Programming Languages

javascript
184084 projects - #8 most used programming language
Less
1899 projects
shell
77523 projects

Projects that are alternatives of or similar to handy-scroll

Iced
A cross-platform GUI library for Rust, inspired by Elm
Stars: ✭ 12,176 (+81073.33%)
Mutual labels:  widget, user-interface
Phaser Ui Tools
Functions for creating a UI in Phaser. Rows, columns, viewports, scrollbars, stuff like that.
Stars: ✭ 187 (+1146.67%)
Mutual labels:  scrollbar, user-interface
floating-scroll
Lightweight jQuery plugin providing floating scrollbar functionality
Stars: ✭ 72 (+380%)
Mutual labels:  scrollbar, user-interface
Finalcut
A text-based widget toolkit
Stars: ✭ 244 (+1526.67%)
Mutual labels:  widget, user-interface
SNIndexedScroller
Custom indexed scroller
Stars: ✭ 29 (+93.33%)
Mutual labels:  user-interface
material
Material Design Widgets for PySide and PyQt4
Stars: ✭ 66 (+340%)
Mutual labels:  widget
wp-parsidate
Integrates the Solar Hijri (Persian) calendar in WordPress
Stars: ✭ 36 (+140%)
Mutual labels:  widget
cl-bootstrap
Common Lisp web development widget library for Twitter's Bootstrap
Stars: ✭ 16 (+6.67%)
Mutual labels:  widget
smooth-vuebar
Vue directive wrapper for smooth-scrollbar
Stars: ✭ 29 (+93.33%)
Mutual labels:  scrollbar
nhl-my-team-ios-widget
"NHL-MyTeam" Scriptable iOS widget 🏒
Stars: ✭ 16 (+6.67%)
Mutual labels:  widget
now-playing-profile
Originally created by github.com/natemoo-re, a small Spotify widget suitable for your profile! Read the "spotify-setup-guide.md" to get started
Stars: ✭ 32 (+113.33%)
Mutual labels:  widget
a11yAccordion
An accessible and easy to use Accordeon widget.
Stars: ✭ 37 (+146.67%)
Mutual labels:  widget
scrollpup.js
Minimal beautiful bar to show scroll progress. Pure Javascript Plugin.MIT
Stars: ✭ 83 (+453.33%)
Mutual labels:  scrollbar
flutter signature pad
📦 Flutter widget to allow users to sign with finger and export the result as image data.
Stars: ✭ 95 (+533.33%)
Mutual labels:  widget
Pagination
a paging widget based on Qt
Stars: ✭ 22 (+46.67%)
Mutual labels:  widget
widgets
🚀 Dojo - UI widgets.
Stars: ✭ 82 (+446.67%)
Mutual labels:  widget
yii2-selectize-widget
Selectize From Brian Reavis Yii2 Widget
Stars: ✭ 73 (+386.67%)
Mutual labels:  widget
feathersui-starling
User interface components for Starling Framework and Adobe AIR
Stars: ✭ 920 (+6033.33%)
Mutual labels:  user-interface
stagtools
StagTools is a powerful plugin to extend functionality to your WordPress themes offering shortcodes, FontAwesome icons, and useful widgets.
Stars: ✭ 21 (+40%)
Mutual labels:  widget
flutter plugins
Flutter插件集合,好用常用的插件.
Stars: ✭ 22 (+46.67%)
Mutual labels:  widget

handy-scroll

Handy dependency-free floating scrollbar widget

Synopsis

handy-scroll is a dependency-free module which can be used to solve the problem of scrolling some lengthy containers horizontally when those containers don’t fit into the viewport. The widget is just a scrollbar which is attached at the bottom of the container’s visible area. It doesn’t get out of sight when the page is scrolled, thereby making horizontal scrolling of the container much handier.

💡 Tips:

  • If you are rather looking for a jQuery plugin with the same functionality, please check out the sibling project floating-scroll instead.
  • Developing a Vue-based app? Consider using the vue-handy-scroll component.

Usage

The widget requires the CSS file handy-scroll.css to be included on the page (you may also import it in your CSS/LESS files). The module script file handy-scroll.min.js may be added on the web page either via a separate <script> element, or it may be loaded by any AMD/CommonJS compatible module loader.

💡 Tip: If you don’t care about supporting Internet Explorer, feel free to use the file handy-scroll.es6.min.js, which is de facto the same as handy-scroll.min.js but is written in ES6, and is a bit smaller.

The handy-scroll package is available on npm, so you may add it to your project as usual:

npm install handy-scroll

Details & API

The module exports a single object handyScroll which provides the following methods:

  • mount — initializes and “mounts” the widgets in the specified containers;
  • mounted — checks if the widget is already mounted in the given container;
  • update — updates the widget parameters and position;
  • destroy — destroys the widgets mounted in the specified containers and removes all related event handlers;
  • destroyDetached — destroys handy-scroll widget instances whose containers were removed from the document.

Mounting the widget

The only thing required to attach the widget to a static container (whose sizes will never change during the session) is a single call of the handyScroll.mount() method. The method expects a single argument, the target containers reference, which can be either an element, or a list of elements, or a selector.

// mount widget in the specified container element
handyScroll.mount(document.getElementById("spacious-container"));

// mount widgets in all the container elements in the collection
handyScroll.mount(document.getElementsByClassName("spacious-container"));
handyScroll.mount([myDOMElement1, myDOMElement2, myDOMElement3]);

// mount widgets in all the container elements matching the selector
handyScroll.mount(".examples > .spacious-container");

Auto-initialisation

There is another way to mount the handy-scroll widget without writing a single line of JavaScript code. Just add the attribute data-handy-scroll to the desired containers. As the DOM is ready the module will detect all such elements and will mount widgets automatically.

<div class="spacious-container" data-handy-scroll>
    <!-- Horizontally wide contents -->
</div>

Checking widget existence

You may check if the widget is already mounted in the given container by calling the handyScroll.mounted() method.

handyScroll.mount("#spacious-container");
console.log(handyScroll.mounted("#spacious-container")); // true

Updating scrollbar

If you mount the widget in a container whose size and/or content may dynamically change, you need a way to update the scrollbar each time the container’s sizes change. This can be done by invoking the method handyScroll.update() as in the example below.

handyScroll.mount(".spacious-container");
// ... some actions which change the total scroll width of the container ...
handyScroll.update(".spacious-container");

The method expects a single argument, the target containers reference, which can be either an element, or a list of elements, or a selector.

Destroying the widget

To unmount the widget and remove all related event handlers, use the method handyScroll.destroy() as follows:

handyScroll.destroy(".spacious-container");

The method expects a single argument, the target containers reference, which can be either an element, or a list of elements, or a selector.

Destroying detached widgets

If your app completely re-renders a large portion of DOM where handy-scroll widgets were mounted, actual container references are lost, and therefore you cannot unmount the widgets and perform related cleanup using the destroy method. In this case, you may just call the handyScroll.destroyDetached() method, and the module will find all “zombie” instances and will destroy them for you.

handyScroll.mount(".main-view .spacious-container");
// ... the app re-renders the main view ...
document.querySelector(".main-view").innerHTML = "...";
// destroy handy-scroll widgets whose containers are not in the document anymore
handyScroll.destroyDetached();

Special cases

If you want to attach the widget to a container living in a positioned box (e.g. a modal popup with position: fixed) then you need to apply two special indicating class names in the markup. The module detects these indicating class names (they are prefixed with handy-scroll-) and switches to a special functioning mode.

<div class="handy-scroll-viewport"><!-- (1) -->
    <div class="handy-scroll-body"><!-- (2) -->
        <div class="spacious-container">
            <!-- Horizontally wide contents -->
        </div>
    </div>
</div>

The .handy-scroll-viewport element (1) is a positioned block (with any type of positioning except static) which serves for correct positioning of the widget. Note that this element itself should not be scrollable. The .handy-scroll-body element (2) is a vertically scrollable block (with overflow: auto) which encloses the target container the widget is mounted in. After applying these special class names, you may initialise the widget as usual:

handyScroll.mount(".spacious-container");

The handy-scroll.css file provides some basic styles for elements with classes .handy-scroll-viewport and .handy-scroll-body. Feel free to adjust their styles in your stylesheets as needed.

“Unobtrusive” mode

You can make the widget more “unobtrusive” so that it will appear only when the mouse pointer hovers over the scrollable container. To do so just apply the class handy-scroll-hoverable to the desired scrollable container owning the widget.

Live demos

Check out some usage demos here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].