- Developed for modern browsers
- Only 4.1 KB minified
- Made with ♥ by Julian Lloyd
What’s new? See the Change Log
Installation
Download and unzip master.zip and copy scrollReveal.min.js
into your JavaScript directory. Include the file in your project, and instantiate a new scrollReveal object.
Example:
<script src='/js/scrollReveal.min.js'></script>
<script>
window.scrollReveal = new scrollReveal();
</script>
</body>
- GitHub —
git clone https://github.com/julianlloyd/scrollReveal.js.git
- Bower —
bower install scrollReveal.js
Basic Usage
Just add a data-scroll-reveal
attribute to your element(s), and scrollReveal.js will automatically reveal them as they enter the viewport.
Example:
<!-- Using scrollReveal.js with defaults: -->
<div data-scroll-reveal> Hello world! </div>
But wait… It’s more fun if you define your own reveal animations, which you can do using using natural, declarative language.
Example:
<!-- Reveal using custom parameters: -->
<div data-scroll-reveal="enter left and move 50px over 1.33s"> Foo </div>
<div data-scroll-reveal="enter from the bottom after 1s"> Bar </div>
<div data-scroll-reveal="wait 2.5s and then ease-in-out 100px"> Baz </div>
What you enter into the data-scroll-reveal
attribute is parsed for specific words:
- keywords that expect to be followed by a value.
- fillers as natural language sugar. (optional)
keyword: enter
— Controls the vector origin of your animation.
value: top
| right
| bottom
| left
Example:
<!-- Reveal your element with a downward motion: -->
<div data-scroll-reveal='enter top'> Foo </div>
keyword: move
— Controls the distance your element moves during animation.
value: [ integer ]px.
Example:
<div data-scroll-reveal='move 24px'> Bar </div>
keyword: over
— Controls the duration of your animation.
value: [ decimal ]s
Example:
<div data-scroll-reveal='over 1.66s'> Baz </div>
keyword: after/wait
— Controls the delay before your animation begins.
value: [ decimal ]s
Example:
<!-- Both are accepted: -->
<div data-scroll-reveal='after 0.33s'> Mel </div>
<div data-scroll-reveal='wait 0.33s'> Mel </div>
Next, by combining the above options, you can create dynamic reveal animation effects.
Example:
<div data-scroll-reveal='enter top move 50px'> Foo </div>
<div data-scroll-reveal='enter top move 50px after 0.3s'> Bar </div>
<div data-scroll-reveal='enter top move 50px after 0.6s'> Baz </div>
<div data-scroll-reveal='enter top move 50px after 0.9s'> Mel </div>
You can use conjoining filler words for more readable language.
from
the
and
then
but
with
,
Example:
<!-- These 4 lines are equivalent: -->
<div data-scroll-reveal='wait 0.3s, then enter left and move 40px over 2s'> Foo </div>
<div data-scroll-reveal='enter from the left after 0.3s, move 40px, over 2s'> Bar </div>
<div data-scroll-reveal='enter left move 40px over 2s after 0.3s'> Baz </div>
<div data-scroll-reveal='enter left, move 40px, over 2s, wait 0.3s'> Mel </div>
You can pass an object to the constructor with your desired default configuration.
<script src='js/scrollReveal.min.js'></script>
<script>
var config = {
after: '0s',
enter: 'bottom',
move: '24px',
over: '0.66s',
easing: 'ease-in-out',
viewportFactor: 0.33,
reset: false,
init: true
};
window.scrollReveal = new scrollReveal( config );
</script>
</body>
Tip: The config object above shows the actual scrollReveal default values.
The scrollReveal.init()
method checks the DOM for all elements with data-scroll-reveal
attributes, and initializes their reveal animations. By default, this method fires on instantiation, but by amending our config object with init: false
, one can then call scrollReveal.init()
as desired.
Example:
<script src='js/scrollReveal.min.js'></script>
<script>
window.scrollReveal = new scrollReveal( {init: false} );
// Here you might load another library, or query an API...
// Now we initialize scrollReveal:
scrollReveal.init();
</script>
</body>
Tip: You can call
scrollReveal.init()
more than once, to re-check the DOM.
If set to 0, the element is considered in the viewport as soon as it enters.
If set to 1, the element is considered in the viewport when it is fully visible.
Example:
var config = {
viewportFactor: 0.33
};
// Your reveal animation triggers after 33% of
// your element is visible within the viewport.
Using the reset
keyword makes elements disappear when out of view view, and reveal each time they come into view.
Example:
<div data-scroll-reveal="reset"> Foo </div>
Note: This is not a keyword–value pair,
reset
is a uniquely solitary keyword.
The move
keyword can be replaced with any one of the following:
ease
ease-in
ease-out
ease-in-out
Example:
<div data-scroll-reveal="after 2s, ease-in 32px and reset over .66s"> Foo </div>
Community feedback and involvement is highly encouraged. (See Open Issues.)
scrollReveal.js was inspired by the awesome cbpScroller.js by Mary Lou. Copyright © 2014 Codrops.
The MIT License (MIT)
Copyright © 2014 Julian Lloyd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.