Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Last active February 26, 2019 09:10
Show Gist options
  • Save LeanSeverino1022/6b926797f34d46e06e449be37edebad7 to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/6b926797f34d46e06e449be37edebad7 to your computer and use it in GitHub Desktop.
Position horizontal scroll bar at center of DIV (jQuery (2.1.1))
/*position horizontal scroll bar at center of DIV*/
// useful when for example the min-width of a scrollable container is wider than the viewport. Like in the t-shirt demo proj, I wanted the user to see the center of the shirt on load, rather than have the user need to scroll
function centerHScrollBar(){
var outerContent = $('.product-view');
var innerContent = $('.pillow-contain-show');
outerContent.scrollLeft( (innerContent.width() - outerContent.width()) / 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment