Please find the below function to make auto scroll of the page based on the parameter provided.
/** Auto Scroll to Top. */
var autoScrollToTop = function (value) {
//var scrollTopVal = 90;
if (typeof value == 'undefined') {
var scrollTopVal = 90;
}
else if ((value != "") && isNaN(value)) {
scrollTopVal = $(value).offset().top;
}
else if (value > 0 ) {
scrollTopVal = value;
}
//alert(scrollTopVal);
$('html, body').animate({ scrollTop: scrollTopVal }, 500); // 500 (mili second) or 'slow'
};
// The function can be called as below;
autoScrollToTop() // Type: Blank, (Default:90)-> Scroll to 90px from top.
autoScrollToTop(0) // Type: Zero -> Top scroll to very top
autoScrollToTop(150) // Type: Numeric -> Scroll to Provided Numeric value(150px) from top.
autoScrollToTop('.className'); // Type: 'className' -> Auto calculate the distance from top to that className component
autoScrollToTop('#elementID'); // Type: 'elementID' -> Auto calculate the distance from top to that elementIDcomponent
No comments:
Post a Comment
Please post any queries and comments here.