Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added firefox & IE support + fixed callback not firing. #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This is a simple function for animating scroll.
- If user scrolls while animation is running, scroll animation would be immediately canceled.
- Use as a single script or through bower.

## Browser support

- If you want full browser support include this library: https://github.com/mathiasbynens/document.scrollingElement

## Example usage

```javascript
Expand Down
18 changes: 14 additions & 4 deletions animatedScrollTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

var animatedScrollTo = function (element, to, duration, callback) {
var start = element.scrollTop,
change = to - start,
animationStart = +new Date();
change = to - start,
animationStart = +new Date();
var animating = true;
var lastpos = null;

Expand All @@ -33,18 +33,28 @@
lastpos = val;
element.scrollTop = val;
}
if (now > animationStart + duration) {
if (now > animationStart + duration || isBottomPage(element)) {
element.scrollTop = to;
animating = false;
if (callback) { callback(); }
}
};

requestAnimFrame(animateScroll);

var isBottomPage = function(element){
var scrollTop = element.scrollTop;
var scrolledToBottom = (scrollTop + window.innerHeight) >= element.scrollHeight;

if(scrolledToBottom){
return true;
}
}
};

if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = animatedScrollTo;
} else {
window.animatedScrollTo = animatedScrollTo;
}
})(window);
})(window);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "animated-scrollto",
"name": "animated-scrollto-gijs",
"version": "1.1.0",
"description": "Animated scrolling without any dependency on libraries",
"main": "animatedScrollTo.js",
Expand Down