-
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 2 commits
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,21 @@ | ||
| 'use strict'; | ||
| document.addEventListener('DOMContentLoaded', function () { | ||
| 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') { | ||
|
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. Tag name comparisons should use uppercase (tagName is uppercase) or normalize with |
||
| const targetSrc = event.target.src; | ||
|
|
||
| largeImg.src = targetSrc; | ||
| } | ||
|
|
||
| if (event.target.tagName === 'A') { | ||
| const imgInsideA = event.target.querySelector('img'); | ||
|
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. Potential improvement: When the user clicks an element, |
||
|
|
||
| if (imgInsideA) { | ||
| largeImg.src = imgInsideA.src; | ||
|
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 handling clicks on an |
||
| } | ||
| } | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| body { | ||
|
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. If |
||
| 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.
Good: you wrapped initialization in DOMContentLoaded which ensures elements exist before use. However, there's a potential runtime error: you call
gallery.addEventListener(...)without checking thatgalleryis non-null. If the.galleryelement is missing, this will throw. Add a null check (e.g.,if (!gallery) return;) before adding the listener.