Skip to content

Instantly share code, notes, and snippets.

@tun
Created January 22, 2013 18:47
Show Gist options
  • Save tun/4597189 to your computer and use it in GitHub Desktop.
Save tun/4597189 to your computer and use it in GitHub Desktop.
$(function(){
$('nav#main a, nav#foo a').click(function(){
var where = $(this).attr('href')
if ( where == '#top') {
var slideto = '0'
} else {
var slideto = $(where).offset().top
}
$('html:not(animated), body:not(animated)').animate({scrollTop: slideto }, 'slow')
return false
})
})
@Jzarecta
Copy link

Jzarecta commented Apr 3, 2014

Donde insertas los anchors en el cuerpo del HTML.

@alexserver
Copy link

no está insertando anchors, está asignando un evento 'onclick' a los anchors, y haciendo una animación slide.

@ialex
Copy link

ialex commented Apr 6, 2014

basicamente necesitas un html como esto,

<a href="#misection"></a>

<div id="section1"></div>
<div id="misection"></div>
<div id="otrasection"></div>

Cada que alguien da click en un enlace el js actua lee el href y te lleva al div que tiene ese id. en este caso el primer anchor te llevaria al div que tiene como id misection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment