Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
Added a second parameter to setScrollTop. Fixes #149
Browse files Browse the repository at this point in the history
The second parameter `force` can be set to true if no transition is desired.
Skrollr will then jump straight to the new position.
  • Loading branch information
Alexander Prinzhorn committed Feb 24, 2013
1 parent 89e174e commit a82abf2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,12 @@ var offset = s.relativeToAbsolute(document.getElementById('foo'), 'top', 'bottom

Returns the current scroll offset in pixels. Normalizes different browser quirks and returns the iScroll y-position in case of skrollr.mobile.

### setScrollTop(top)
### setScrollTop(top[, force = false])

Sets the top offset using `window.scrollTo(0, top)` on dektop or `iscroll.scrollTo(0, -top)` when using skrollr.mobile.

When `force` is set to `true`, skrollr will jump to the new position without any kind of transition. By default the global `smoothScrolling` setting applies.

### animateTo(top[, options])

Animates the scroll position from current position to `top`. Possible options are
Expand Down
2 changes: 1 addition & 1 deletion dist/skrollr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/circular_motion.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
render: function(data) {
//Loop
if(data.curTop === data.maxTop) {
this.setScrollTop(0);
this.setScrollTop(0, true);
}
}
});
Expand Down
8 changes: 7 additions & 1 deletion src/skrollr.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,13 @@
return !!_scrollAnimation;
};

Skrollr.prototype.setScrollTop = function(top) {
Skrollr.prototype.setScrollTop = function(top, force) {
//Don't do smooth scrolling (last top === new top).
if(force === true) {
_lastTop = top;
_forceRender = true;
}

//skrollr.iscroll is an instance of iscroll available in mobile mode
if(skrollr.iscroll) {
//Notice the minus.
Expand Down

0 comments on commit a82abf2

Please sign in to comment.