jQuery Scroll Plugin - by Fazlur Rahman
/*
Nextframe jQuery Plugins
Author : Fazlur Rahman
Website : http://fazlurrahman.com
Version : 1.0.0
Required Libraries :
- jQuery
- jQuery Easing
*/
( function($) {
$.fn.scrollToTop = function( _duration, _easing ) {
// Check Options Parameters
if ( isNaN( _duration ) || _duration === '' ) _duration = 1000;
if ( _easing === '' ) _easing = 'easeOutQuart';
// Bind Click Event
this.click( function (event) {
event.preventDefault();
$("html, body").animate({ scrollTop: "0" }, _duration, _easing);
});
};
$.fn.scrollToLink = function( _offset, _duration, _easing, _is_change_url ) {
// Check Options Parameters
if ( isNaN( _offset ) || _offset === '' ) _offset = 0;
if ( isNaN( _duration ) || _duration === '' ) _duration = 1500;
if ( _easing === undefined || _easing === '' ) _easing = 'easeInOutExpo';
if ( _is_change_url === undefined || _is_change_url === '' ) _is_change_url = false;
// Bind Click Event
this.click( function (event) {
event.preventDefault();
var anchor = $(this);
var href = anchor.attr('href');
// Change URL
if ( _is_change_url ) history.pushState(null, null, href);
// Animate Scroll
$('html, body').stop().animate({
scrollTop: $( href ).offset().top - _offset
}, _duration, _easing);
});
};
} (jQuery) );