Skip to content

Commit

Permalink
Merge pull request #15 from justMoritz/m/004/sascrollupdate
Browse files Browse the repository at this point in the history
Fixed problem with saScroll and added scroll intercept.
  • Loading branch information
justMoritz committed Jan 19, 2018
2 parents d7f235d + 9be7c64 commit 1547afd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scrollimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,24 @@ var scrollimate = (function( window, $ ){
*/
var saScroll = function() {
console.log('saScroll initiated');
$('[href^="#"]').click(function(){
var smoothAnchorScrollTime = 500 + (Math.floor($($(this).attr("href")).offset().top))/2;
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, smoothAnchorScrollTime);
$('[href^="#"]').click(function(){
var $this = $(this);
if( $($this.attr('href')).length && $this.attr('href') !== '#' ){
var smoothAnchorScrollTime = 500 + (Math.floor($($this.attr("href")).offset().top))/2;
var scrollEvents = "scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove";
var $page = $('html, body');

$page.on(scrollEvents, function(){
$page.stop();
});
$page.animate({
scrollTop: $( $this.attr('href') ).offset().top
}, smoothAnchorScrollTime).promise().then(function() {
$page.off(scrollEvents);
});
return false;
});
}
});
};


Expand Down

0 comments on commit 1547afd

Please sign in to comment.