afonsoalban
1/6/2016 - 1:28 PM

Scroll to functions

JS simples para rolar a página.

window.scrollTo = function (target) {
	$("html, body").animate({ scrollTop: $(target).offset().top }, 1000);
}
window.scroll = function (e) {
  var $target;
  
	if(typeof e == 'string'){
		$target = $(e);
	} else {
		e.preventDefault();
		var $botao = $(e.currentTarget);
		
		if( typeof $botao.attr('href') !== 'undefined' ){
			$target = $( $botao.attr('href') );
		} else if( typeof $botao.attr('data-target') !== 'undefined' ) {
			$target = $( $botao.data('target') );
		}
	}

	$("html, body").animate({ scrollTop: $target.offset().top }, 1000);
}