6.7. Centering an Element Within the Viewport
6.7.1. Problem
You want to scroll the window to center an element within
the viewport.
6.7.2. Solution
Get the viewport’s dimensions; determine the width, height, and
offset of the element; and use a little math to center the element in
the viewport:
You are currently reading a PREVIEW of this book.
Get instant access to over
$1 million worth of books and videos.
Start a Free Trial