-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating an Accessible Image Carousel #166
Comments
Hi Alexander, Firstly, great article. There was only one thing I found that wasn't correct in your article. For improved performance, I’m also using the loading="lazy" attribute to enable native lazy loading, which defers loading images that aren’t currently visible. Once we enable overflow scrolling with CSS in a future section, this will defer loading images that are overflowing horizontally beyond the carousel’s client window. By setting loading=lazy, all images with this attribute will be loaded later. This should only be applied to images that are offscreen. Therefore, if you are using the carousel in the first view, this attribute should only be set on the + 4th images. Otherwise it will also defer the loading of images 1, 2 & 3. Your scroll snap problem is probably also caused by this. Regards, Sander van Surksum |
@sandersu Thanks for the feedback! I didn't want to get into the details of how If the carousel is in view on page load and you inspect the network tab, you should see that only the first two images or so get requested (the bottom two images in the following screenshot): Once you scroll the carousel, the remaining images get requested: |
The problem lies in the fact that the browser has to detect whether an image is in the viewport, which takes time. Because the browser has to wait until the IntersectionObserver is available. Generally, do not lazy load images images visible in the viewport See this comparison between lazy in viewport vs non lazy in viewport. |
@sandersu Yup, this is a good point! I had to do that at one point on my own site because Lighthouse was flagging it (LCP images were lazily loaded). If you have control over your carousel (i.e., users aren't uploading dynamic images), and you have control over where on a page it is positioned, it's definitely worth taking this into consideration. |
Hi Alexander |
@shyke I should've probably clarified this in the article, but |
Thanks for the replay.
I probably didn't explain my self right, I understand the concept of the
scroll left value is 0 on RTL.
The thing I couldn't manage to solve is how to set the gallery scrolle
position to the center before load (on the class constrocter) .
Let say I have 3 images so image number 2 should be in the center of the
scrollable container. The only way I manage to that is to listen to window
load event and change the scroller position programmatically but the scroll
is visible to the user so that isn't a good solution.
Another example can be that your gallery on the codepen load with the dear
( photo number 5 ) on the center of the scrollable container.
Again thank you so much for your article
…On Thu, Dec 29, 2022, 6:28 PM Aleksandr Hovhannisyan < ***@***.***> wrote:
@shyke <https://github.com/shyke> I should've probably clarified this in
the article, but scrollLeft is a bit of a misnomer in the DOM. It should
really be called scrollStart. In RTL, scrollLeft will be 0 if the
container has not been scrolled. Once you start scrolling, the values
increase in magnitude but will be negative. I'd recommend taking a look at
the CodePen demo linked in the article:
https://codepen.io/AleksandrHovhannisyan/pen/zYRVoeb.
—
Reply to this email directly, view it on GitHub
<#166 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFI3O7TWWRCDMJKJH4KCFTWPW32RANCNFSM5ZT5NTSQ>
.
You are receiving this because you were mentioned.Message ID:
<AleksandrHovhannisyan/aleksandrhovhannisyan.com/issues/166/1367447282@
github.com>
|
@shyke Oh, I see. I don't think it's possible to programmatically center the carousel on a particular image initially without the user noticing. There's no CSS solution for this that I know of, so you'd need to scroll to that image on window load like you said. |
Hey @AleksandrHovhannisyan Great article!!, I was wondering since you followed the approach of disabling the |
@Pooja22singh I wouldn't recommend taking that approach, as it could confuse users who normally expect the next button to take them to the next image (e.g., an image to the right). |
No description provided.
The text was updated successfully, but these errors were encountered: