JavaScript intersection detection plugin scrollama.js

Add-ons
2026-07-25 22:22 2 次浏览 • 0 次下载 82.7KB
JavaScript intersection detection plugin scrollama.js

How to Use

Basics

You can use this library to simply trigger steps for content such as dots. This is useful if you need more control over interactive elements or do not want to follow the sticky scrollytelling pattern.

You can use any ID/class naming convention you prefer. The HTML structure should look like this:

1
2
3
4
<!--you don't need the "data-step" attr, but can be useful for storing instructions for JS -->
<div class='step' data-step='a'></div>
<div class='step' data-step='b'></div>
<div class='step' data-step='c'></div>
1
2
3
4
5
6
7
8
9
10
11
// Instantiate scrollama
const scroller = Scrollama()
// Set up the instance and pass callback functions
scroller.setup({
step: '.step', // Required
offset: 0.5, // Offset (optional, default = 0.5)
debug: false, // Debug (optional, default = false)
})
.onStepEnter(handleStepEnter)
.onStepExit(handleStepExit)

Sticky graphic

To implement the sticky graphic scrollytelling pattern, you need the following three elements (container, graphic, step). The structure should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- container = ".scroll" -->
<div class='scroll'>
<!-- graphic = ".scroll__graphic" -->
<div class='scroll__graphic'>
<!--graphic / chart code here-->
</div>
<div class='scroll__text'>
<!-- steps = ".step" -->
<div class='step' data-step='a'></div>
<div class='step' data-step='b'></div>
<div class='step' data-step='c'></div>
</div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Instantiate scrollama
const scroller = Scrollama()
// Set up the instance and pass callback functions
scroller.setup({
step: '.scroll__text .step', // required
container: '.scroll', // required (for sticky)
graphic: '.scroll__graphic', // required (for sticky)
offset: 0.5, // optional, default = 0.5
debug: false, // optional, default = false
})
.onStepEnter(handleStepEnter)
.onStepExit(handleStepExit)
.onContainerEnter(handleContainerEnter)
.onContainerExit(handleContainerExit)

API

scrollama.setup([options])

  • step (string): Selector for the step elements that trigger changes. Required.

  • container (string): Selector for the element containing all scrolling content. Optional.

  • graphic (string): Selector for the graphic element that will become fixed. Optional.

  • offset (number, 0 - 1): Distance from the top of the viewport at which a step is triggered. (Default: 0.5)

  • progress (boolean): Whether to trigger incremental step progress updates. (Default: false)

  • debug (boolean): Whether to display visual debugging tools. (Default: false)

星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare