Fork me on GitHub

Features

  • Only 9kB and framework-independent
  • Highly optimized
  • Vertical and horizontal scrollbars support
  • Both ltr and rtl text direction support (with smart detection)
  • Nested scrollbars support
  • Custom events
  • Animated scrollTo and scrollIntoView
  • Auto update on content/scroll area change
  • Integrated page bounce fix for iOS
  • Works on any modern browser (IE11+)
  • Optional jQuery plugin

Usage

Simple use case

new Optiscroll(element)
or if you prefer the jQuery flavour
$('selector').optiscroll()

Try it out:

Don't see any difference?
By default Optiscroll does not create custom scrollbars on iOS, Android and OSX w/ trackpad. However, the API and the custom events will work across all platforms.

Forced scrollbars with inline appearance

new Optiscroll(element, { forceScrollbars: true })
or if you prefer the jQuery flavour
$(element).optiscroll({ forceScrollbars: true })

If you decide to force the scrollbars, they will be created on all platform. However, this is not recommended because on iOS the position will be updated when the momentum scrolling ends.

API

scrollTo ( destX, destY [, duration] )

Scroll to a specific point with a nice animation. If you need to scroll a single axis then set the opposite axis destination to false. Duration could be auto (based on the distance) or in milliseconds.

scrollTo(, , )

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.

Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.

Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum.

Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima.

Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum



scrollIntoView (elem [, duration, delta])

Scrolls the element into view. The alignment will be driven by the nearest edge. Duration could be auto (based on the distance) or in milliseconds. Delta is an optional distance from the edge.

scrollIntoView(el, , )

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.

Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.

Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.

Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem.

Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum.

Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima.

Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum

Custom events

sizechange

This event is fired on clientWidth/clientHeight changes of the optiscroll element, or on scrollWidth/scrollHeight changes of the scroll area.

scrollstart

This event is fired when the user starts scrolling. It's not fired again until a scrollstop event gets fired. See scrollstop event for further details.

scroll

This event is fired while user scrolls. This event differs from the native one as it is throttled. It's fired accordingly with the scrollMinUpdateInterval value.

scrollstop

This event is fired when the user stops scrolling. The wait time before this event gets fired is defined by the scrollStopDelay option.

scrollreachedge

This event is fired when the user scrolls to any edge (top/left/right/bottom). There are also edge specific events: scrollreachtop, scrollreachbottom, scrollreachleft, scrollreachright. The "generic" event name is fired before the specific one.