Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
What Im trying to do is make it so that if you clicking on a button, it scrolls horizontzly(smoothly) to a specific div on the page. How to do that?

What I have tried:

I have tried offset.left but it doesnt works properly
Posted

1 solution

Something like this should work:
JavaScript
var left = $("#idOfTheTargetHere").offset().left;
$("html, body").animate({ scrollLeft: left }, 500);

Change #idOfTheTargetHere to the jQuery selector which selects the element you want to scroll into view.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900