Created
October 10, 2016 11:12
-
-
Save davidchc/6046479bd86de58e1a16347f87c08844 to your computer and use it in GitHub Desktop.
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
/** | |
Element: Elemento Selecionado | |
Speed : Velocidade do Efeito | |
Increment: Valor que deseja incrementar na posição*/ | |
function goTo(element, speed, increment){ | |
var href = element.attr('href'); | |
var top = $(href).offset().top; | |
if(typeof increment !== 'undefined'){ | |
top += increment; | |
} | |
$("html,body").animate({scrollTop: top}, speed); | |
} | |
$(function(){ | |
//Associa o evento click no link | |
$('#top a').click(function(e){ | |
e.preventDefault(); | |
//Pega o href do link, pra saber qual seção | |
var section = $(this).attr('href'); | |
//inicia a variavel com valor 0 | |
var increment = 0; | |
//se for a seção service, acrescenta mais 10px | |
if(section == '#service'){ | |
increment = 10; | |
} | |
//Chama a função | |
gotTo($("#service"), 500, increment); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment