ayuda scroll animado a un ancla
Publicado por manu (5 intervenciones) el 15/03/2013 20:44:45
Hola buenas:
Tengo el siguiente problema y agradeceria alguna ayuda....
Tengo el siguiente codigo (mas o menos):
y el siguiente codigo jquery:
esto me funciona si los section los pongo fuera del div, pero yo lo que quiero es hacer el scroll
dentro de ese div y no se como.... Alguien me puede ayudar?
gracias.
Tengo el siguiente problema y agradeceria alguna ayuda....
Tengo el siguiente codigo (mas o menos):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<a href="#uno" >uno</a>
<a href="#uno" >dos</a>
<a href="#uno" >tres</a>
<a href="#uno" >cuatro</a>
<div id="contenido">
<section id="uno">
xxxxxxx
xxxxxx
xxxx
xxx
</section>
<section id="dos">
xxxxxxx
xxxxxx
xxxx
xxx
</section>
<section id="tres">
xxxxxxx
xxxxxx
xxxx
xxx
</section>
<section id="cuatro">
xxxxxxx
xxxxxx
xxxx
xxx
</section>
</div>
y el siguiente codigo jquery:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
$target = $(this.hash);
$target2 = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
esto me funciona si los section los pongo fuera del div, pero yo lo que quiero es hacer el scroll
dentro de ese div y no se como.... Alguien me puede ayudar?
gracias.
Valora esta pregunta


0