---
name: "up.scroll"
area: "API"
kind: "JavaScript function"
parent: "up.viewport module"
visibility: "deprecated"
url: "https://unpoly.com/api/up.scroll"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.viewport module](https://unpoly.com/api/up.viewport.md)</nav>

# up.scroll(viewport, scrollPos, [options])

**This feature has been deprecated**. Use [`Element#scrollTo()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo) instead.

Load [`unpoly-migrate.js`](https://unpoly.com/changes/upgrading.md) 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-y: scroll`.

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Animating the scrolling motion](#animating-the-scrolling-motion)
- [Parameters](#parameters)

</nav>

## Example {#example}

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

```js
up.scroll('.main', 100)
```

## Animating the scrolling motion {#animating-the-scrolling-motion}

The scrolling can (optionally) be animated.

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

---

## Parameters {#parameters}

### viewport {#viewport}

(required)

The container element to scroll.

Type: string | [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [jQuery](https://learn.jquery.com/using-jquery-core/jquery-object/)

### scrollPos {#scrollPos}

(required)

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

Type: number

### [options.behavior='instant'] {#options.behavior}

(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.

Type: string

