Last active
September 26, 2018 14:49
-
-
Save fernandosavio/3717335 to your computer and use it in GitHub Desktop.
Markup Scroller
This file contains 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
/** | |
* === Scroller === | |
* Basta adicionar a classe "scroller" para algum elemento e atribuir o seletor ao atributo href ou data-target; | |
* Exemplos: | |
* <a href="#wrapper" class="scroller">Topo</a> | |
* <span class="scroller" data-target="#wrapper">Topo</span> | |
*/ | |
jQuery(document).ready(function(){ | |
var screen = $('html, window, body'), | |
regex = /.*(?=#[^\s]+$)/; //strip for ie7 | |
$("body").on('click', ".scroller", function(e){ | |
var $this = $(this), | |
href, | |
target = $this.data('target') | |
|| e.preventDefault() | |
|| (href = $this.attr('href')) && href.replace(regex, ''); | |
screen.animate({ 'scrollTop': $(target).offset().top }, { | |
duration: 500, | |
easing: 'swing' | |
}); | |
e.preventDefault(); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment