Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need smooth scrolling to a div when anchor tag with id is clicked instead of jumping to that div [duplicate]

<div id="slider">
    <div id="pro1"></div>
    <div id="pro2"></div>
    <div id="pro3"></div>
</div>

<div id="thumb">
    <a href="#pro1"> <img id="tpro1" src="projects/tpro5.jpg" style="height: 100%;"></a>
    <a href="#pro2"> <img id="tpro2" src="projects/tpro5.jpg" style="height: 100%;"></a>
    <a href="#pro3"> <img id="tpro3" src="projects/tpro5.jpg" style="height: 100%;"></a>
</div>

This is the code i worked with, when i click on the link it is just jumping to that div so i want some animated horizontal scroll to show that div

thanks

like image 874
W I Z A R D Avatar asked Sep 25 '13 17:09

W I Z A R D


1 Answers

Did u solved the problem already?

look, i tried this and it worked for me so, i think it can work for u ;) Dont even need the element < a >

$("#thethingyougonnaclick").click(function() {
    $('html, body').animate({ scrollTop:$("#theelementidtoscroll").offset().top}, 500);
});
like image 145
Mirelli Avatar answered Oct 12 '22 13:10

Mirelli