Skip to content

Commit

Permalink
Merge pull request #23 from justMoritz/justMoritz-saScroll-callback
Browse files Browse the repository at this point in the history
Added ability to add a callback to saScroll
  • Loading branch information
justMoritz committed Nov 7, 2019
2 parents cb49b2c + 8bd88da commit edafef2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -180,6 +180,10 @@ Alternatively, you can *force* the scroll by calling the method with a force arg

`scrollimate.saScroll('force')`

There is also a provision for a callback, just remember to decide on the force parameter first. Usage:

`scrollimate.saScroll( false, you-callback() )`


_

Expand Down
7 changes: 6 additions & 1 deletion scrollimate.js
Expand Up @@ -203,8 +203,10 @@ var scrollimate = (function($){
* Page is animated to scroll from the top to the element that that matches
* the href attribute.
* return false to prevent default
* you can pass a callback into the function call, which will execute as soon as the animation is over
*/
var saScroll = function(force) {
var saScroll = function(force, callback) {
callback = callback || false;
console.log('saScroll initiated');
$('[href^="#"]').click(function(){
var $this = $(this);
Expand All @@ -225,6 +227,9 @@ var scrollimate = (function($){
scrollTop: $( $this.attr('href') ).offset().top
}, smoothAnchorScrollTime).promise().then(function() {
$page.off(scrollEvents);
if( callback ){
callback();
}
});
return false;
}
Expand Down

0 comments on commit edafef2

Please sign in to comment.