Onepage scroll webpage in component, inspired by Apple iPhone page.
Install with component(1):
$ component install lepture/onepage
var Onepage = require('onepage')
var onepage = new Onepage(document.getElementById('container'));
Onepage
accepts two parameters: element
and options
. The given
element is the father node of each page. For example:
<div class="container">
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
</div>
div.container
is a good element, and every div.page
will be one page.
You can control the animation by options.
- duration: transform duration for scrolling, default is
800
. - timingFunction: function for transform, default is
ease
. - wheelDelta: min wheelDelta value for scrolling, default is
100
. - pagination: create pagination or not, default is
true
. - keyboard: bind keyboard control or not, default is
true
. - loop: loop control, default is
down
, other options are:up
andboth
.
Onepage can trigger events. You can subscribe an event by:
onepage.on('move', function(page) {
console.log(page);
});
- move(page): when page moves
- end(page): when animation end
You can subscribe events with: on
, once
. You can remove an event with
off
.
Learn more about event emitter at component/emitter.
Move to the the given page number. Page begin with 0.
onepage.move(2)
// move to the 3rd page.
Current active page number.
The container element.
Array of pages in the container.
Pagination element.
Last animation time.
MIT