I have created a website with the following design:
(Caution: The site is built using AngularJS on a server that may not serve it correctly - please visit directly instead of using browser reload.)
However, I am facing two conflicting requirements...
- The images should scale down when viewed on smaller screens or narrow browser windows.
- There is a link that directs users to a specific section called "HEADER" on the page.
My initial solution for requirement #1 was straightforward...
img {
max-width: 100%;
}
But scrolling to the HEADER section didn't work because the browser couldn't determine image heights initially. So, I decided to add width and height attributes to all my images thinking this would fix it.
However, adding dimensions caused the images to be distorted on narrow screens. To address this, I made further adjustments to my CSS...
img {
max-width: 100%;
height: auto;
}
While this resolved the image distortion issue, now the browser once again couldn't accurately determine image heights leading to incorrect scrolling on page load.
I'm wondering if there's a way to instruct the browser to scale images down to fit their containers while maintaining a known aspect ratio so that placeholders are correctly sized before image loading?
If it were a traditional webpage, using window.onload to trigger scrolling would have worked (Refer to http://jsfiddle.net/nbS3F/1/) since it waits for all images to load. However, the website I'm working on is a single-page application implemented in AngularJS, so by the time new images start loading, the load event has already occurred.