-
-
Save ScottPhillips/4138804 to your computer and use it in GitHub Desktop.
Animate scrolling to an element or offset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* requires jQuery | |
* usage: | |
* Scroller.to({ offset: 100 }); | |
* Scroller.to({ target: $('#main') }); | |
* | |
* advanced usage (with additional easing function not provided here) | |
* Scroller.to({ target: $('#main'), delay: 500, multiplier: 1.5, easing: 'easeOutQuad' }); | |
*/ | |
var Scroller = (function() | |
{ | |
var scroll = { | |
options: { | |
el: $('html:not(:animated),body:not(:animated)'), | |
multiplier: 1, | |
offset: undefined, | |
easing: 'swing', | |
delay: 0 | |
}, | |
_scrolling: false | |
}; | |
scroll.to = function(options) | |
{ | |
var height = { | |
top: $(window).scrollTop(), | |
doc: $(document).height(), | |
win: $(window).height() | |
}; | |
if (height.doc <= height.win) { | |
return; | |
} | |
var config = $.extend({}, scroll.options); | |
config = $.extend(config, options || {}); | |
config.offset = isNaN(config.offset) ? config.target.offset().top : config.offset; | |
var offset = config.offset, | |
distance = Math.abs(height.top - offset); | |
if (height.top < offset) { | |
var max = height.doc - height.win; | |
if (offset > max) { | |
distance -= offset - max; | |
} | |
} | |
if (distance) { | |
if (scroll._scrolling) { | |
scroll.stop(); | |
} | |
scroll._scrolling = true; | |
scroll.timeout = window.setTimeout(function() { | |
config.el.animate({ scrollTop: Math.floor(offset) }, distance * config.multiplier, config.easing, function() | |
{ | |
scroll._scrolling = false; | |
}); | |
}, config.delay); | |
} | |
}; | |
scroll.stop = function() | |
{ | |
if (scroll.timeout) { | |
window.clearTimeout(scroll.timeout); | |
scroll.timeout = null; | |
} | |
scroll.options.el.stop(); | |
scroll._scrolling = false; | |
}; | |
scroll.isScrolling = function() | |
{ | |
return scroll._scrolling; | |
}; | |
return scroll; | |
})(); |
My experience with rabbit roofing was outstanding—they explained the entire process, stuck to the timeline, and delivered a roof that looks amazing.
college admissions consultant helps students build strong applications and choose the right schools. A college admissions consultant provides strategic planning for every step. https://sayhellocollege.com/
To watch movies and TV shows, one of the best applications is Smart Play APK. It offers premium content for free, and you can also download the movies in the application.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
minecraft java android apk seçeneği, oyunu hızlı ve kolay bir şekilde elde etmek isteyenler içindir.
Resmî mağazalarda ücretli olan içeriklere ücretsiz erişim sunabilir.