1.0.12 • Published 7 years ago

scrollanimate v1.0.12

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

ScrollAnimate NPM version

Animate on scroll.

Preview

Use

If you want to stop the scroll during animations

html,
body {
	overflow: hidden;
}

#wrapper {
	overflow: auto;
}

Import ScrollAnimate.js

// In index.js
import ScrollAnimate from '../../lib/scrollAnimate'
// Or in index.html
<script src="scrollAnimate.js"></script>

Init scrollAnimate

var scrollAnimate = new ScrollAnimate(wrapper, onAnimatingUpdate)

// If you want the scroll to stop during animation,
// use onAnimatingUpdate to update the wrapper overflow like so :
function onAnimatingUpdate(isAnimating) {
	document.getElementById('wrapper').style.overflow = (isAnimating ? 'hidden' : 'auto')
}
NameTypeDescription
wrapperDOM elementMain wrapper, scrollAnimate add event listeners to this wrapper
onAnimatingUpdatefunction(isAnimating)Callback triggered when the animating state change

Create new animation

var animation = scrollAnimate.create(element, triggerOffsetTop, scrollForComplete, onProgressUpdate)
NameTypeDescription
elementDOM elementElement animated, required to determine when the animation should trigger
triggerOffsetTopintAdd offset top before animation triggers
scrollForCompleteintAmount of virtual scroll required to complete the animation, the more the longer
onProgressUpdatefunction(progress)Callback when animation progress update. progress is between 0 and 1

Example

import ScrollAnimate from 'scrollAnimate'

let wrapper = document.getElementById('wrapper')
let timeline1 = document.getElementById('timeline1')
let timeline2 = document.getElementById('timeline2')

let scrollAnimate = new ScrollAnimate(wrapper, onAnimatingUpdate)

function onAnimatingUpdate(isAnimating) {
	wrapper.style.overflow = (isAnimating ? 'hidden' : 'auto')
}

let animation1 = scrollAnimate.create(timeline1, 150, 1000, (progress) => {
	timeline1.style.width = progress * 100 + '%'
})

let animation2 = scrollAnimate.create(timeline2, 150, 1000, (progress) => {
	timeline2.style.width = progress * 100 + '%'
})

Todo

  • Reverse mode
  • Tests
1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago