-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add task solution #1750
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
base: master
Are you sure you want to change the base?
add task solution #1750
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,17 @@ | ||
| 'use strict'; | ||
| const gallery = document.querySelector('.gallery'); | ||
| const largeImg = document.querySelector('#largeImg'); | ||
|
|
||
| // eslint-disable-next-line no-shadow | ||
| gallery.addEventListener('click', function (event) { | ||
| if (event.target.tagName === 'img') { | ||
| const targetSrc = event.target.src; | ||
|
|
||
| largeImg.src = targetSrc; | ||
| } | ||
|
|
||
| if (event.target.tagName === 'a') { | ||
| const imgInsideA = event.target.querySelector('img'); | ||
|
|
||
| largeImg.src = imgInsideA.src; | ||
| } | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good: you wrapped initialization in DOMContentLoaded and use event delegation. However, there's one remaining risk: if the querySelector calls fail (elements missing), |
||
| justify-content: center; | ||
| min-height: 100vh; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When comparing tag names, |
||
|
|
||
|
|
@@ -17,8 +17,8 @@ li { | |
| width: 450px; | ||
| } | ||
| &__list { | ||
| margin-top: 0; | ||
| display: flex; | ||
| margin-top: 0; | ||
| padding-left: 0; | ||
| } | ||
| &__img { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
document.querySelectorfails to find the elements,galleryorlargeImgwill be null which will cause runtime errors when adding the event listener or setting.src. Consider guarding against missing elements or ensuring the DOM elements exist before running this script (e.g., run after DOMContentLoaded or check for null).