Smooth scroll to an element, or to top of page, or to all the anchor elements
/* UI Behaviour: Smooth scroll to top of page */
function nms_scroll_page_to(position, speed) {
$('html, body').animate({
scrollTop: position
//}, speed);
}, {duration: speed, easing: 'easeInOutCubic'}); //with easings library
}
/* UI Behaviour: Smooth scroll to an element */
function nms_scroll_to(element, speed) {
$('html, body').animate({
scrollTop: $(element).offset().top - 65 //navbar height
//}, speed);
}, {duration: speed, easing: 'easeInOutExpo'}); //with easings library
}
/*
Smooth scroll to all anchor elements in page
https://css-tricks.com/snippets/jquery/smooth-scrolling/
*/
$(function () {
$('a[href*=#]:not([href=#])').click(function () {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
//este fragmento se puede sustituir por mi funcion
//ej. plEx_scroll_to(target, 500);
$('html,body').animate({
scrollTop: target.offset().top
}, 500);
return false;
}
}
});
});