Edit this page

up.viewport up.scroll(viewport, scrollPos, [options])
JavaScript function

This feature has been deprecated. Use Element#scrollTo() instead.

Load unpoly-migrate.js to polyfill deprecated features.

Scrolls the given viewport to the given Y-position.

A "viewport" is an element that has scrollbars, e.g. <body> or a container with overflow-x: scroll.

Example

This will scroll a <div class="main">...</div> to a Y-position of 100 pixels:

up.scroll('.main', 100)

Animating the scrolling motion

The scrolling can (optionally) be animated.

up.scroll('.main', 100, { behavior: 'smooth' })

Parameters

viewport stringorElementorjQuery

The container element to scroll.

scrollPos number

The absolute number of pixels to set the vertical scroll position to.

[options.behavior='instant'] string optional

When set to 'instant', this will immediately scroll to the new position.

When set to 'smooth', this will scroll smoothly to the new position.