Skip to content

Instantly share code, notes, and snippets.

@zazk
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save zazk/d1b524f66d771d53f50a to your computer and use it in GitHub Desktop.

Select an option

Save zazk/d1b524f66d771d53f50a to your computer and use it in GitHub Desktop.
JS. JQuery. Menú animado para secciones. Landing
// Función cuando carga la página - OPCIONAL
$(function(){
// Animacion -------------------------------------------------
// Para todos los enlaces - Modificar el selector css que necesite
$('a[href*=#]').click(function() {
// Validar los "/"
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
//Enlace a Seccion #seccion
var $target = $(this.hash);
// Validar que haya una sección
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
// Validar la seccion
if ($target.length) {
// Obtener la posición y de la sección a dónde se desea moverse
var targetOffset = $target.offset().top;
// Ejecutar el scroll
$('html,body').animate({scrollTop: targetOffset}, 1000);
// Salir
return false;
}
}
});
// Final Animacion -------------------------------------------------
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment