Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
austenpayan
10,218 PointsHorizontal Scrolling div
I have a container div that is the width of the page. Inside the div is an image that is very wide (it's a picture of a polespear), and the container is set to overflow:scroll so that a user can horizontally scroll and scan the entire length of the polespear image.
The designer wants the polespear to appear pointing to the right. When the page loads, the scrolling div naturally begins with the scrolling bar at the left. The visual problem with this is that the butt of the polespear is what appears on load, instead of the head as in the design mockup.
Is there a in way in Javascript or perhaps CSS that enables a horizontal scroll box to begin at the right on load, instead of the automatic left?
1 Answer
Andrew Shook
31,709 PointsI don't know of any way to do this in css, but there might. I do know how to do it with jQuery though.
$("div with overflow:scroll").animate({scrollLeft: $(this).width()}, milliseconds you want the animation to last);
or
$("div with overflow:scroll").scrollLeft($(this).width());
for instant scrolling. I think the animation might be nice effect though.
austenpayan
10,218 Pointsaustenpayan
10,218 PointsThanks! This code was correct except instead of (this) I had to apply the id of the polespear image inside of the scroller div.
Works great.
Andrew Shook
31,709 PointsAndrew Shook
31,709 PointsYour welcome. I figured the code would be close enough to what you need without me seeing the actually html. Glad I could help.