Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You have been provided with the necessary styling and markup already. Examine chapter 0 9 - project 0 2 . html in the editor of
You have been provided with the necessary styling and markup already. Examine chapter
project
html in the editor of your choice. You will be programmatically adding elements based
on user actions and data in the supplied JSON file.
Examine paintings
json. This data file
consists of an array of paintings. The id of each painting element corresponds to the image file
name
there is a smaller version and a larger version in two different subfolders inside of the
images folder
Each painting also has an array of features. You will be displaying rectangles
based on the xy coordinates of the features. When the user mouses over a feature rectangle, your
page will display the feature description below the painting.
Begin by modifying ch
proj
js and add a DQMContentLoaded event handler. All of your code will be inside that
handler. Your handler will need to use the JSQN parse
method to transform the JSON data into
a JavaScript object. You will also need to loop through the data array and generate a list of
thmbnail images of the paintings inside the supplied
element. To make click processing easier, you will also want to add the id value of the
painting using the dataset property
see Section
You must use event delegation
i
e
a single event handler
to process all clicks in the painting list. When a painting is
clicked, first empty the element
simply by assigning empty string to the innerHTML.
property
This is necessary to remove the previously displayed image features. After
emptying the, display a larger version of the painting
inside the supplied element
and
display its title and artist in the supplied
and
elements. This will require you to find the painting in your painting array that
matches the id value of the clicked thumbnail; you can do this via a simple loop or
make use of the find
function
covered in the next chapter
You will also need to
perform the next two steps as well.
When a new painting is clicked, you will also
need to loop through the features array for that painting and display rectangles on
top of the painting. Each feature has the upper
left and lower
right coordinates for
the feature. Each rectangle will be a
Delta
element that you programmatically construct and append to the. You will need to
assign it the class box
the CSS for this class has been provided
and set the position,
left, top, width, and height properties. The respective values for these properties will
be absolute
the upper
left
x
value from features array element, the upper
left
y
value from features array element, while the width and height are calculated by
subtracting the lower
right
x
y
from upper
left
xy
Note: the left, top, width, and
height properties must include the
px
unit when assigning the value.
Chapter
Summary
For each rectangle, you will also need to set up mouseover and
mouseout event handlers. For the mouseover, you will need to set the textContent
property of the provided description
with the description property of the feature data for that rectangle. For mouseout, simply empty the
content of the textContent. Need help with HTML
JS
document.addEventListenerDOMContentLoaded function
const paintingList document.querySelector#paintinglist";
const figure document.querySelectorfigure;
const h document.querySelectorh;
const h document.querySelectorh;
const description document.querySelector#description";
fetchpaintingsjson"
thenresponse response.json
thendata
data.forEachpainting
const listItem document.createElementli;
const thumbnail document.createElementimg;
thumbnail.src imagesthumbnails$paintingidsmall.jpg;
thumbnail.alt painting.title;
thumbnail.dataset.paintingId painting.id;
listItem.appendChildthumbnail;
paintingList.appendChildlistItem;
;
paintingList.addEventListenerclic
NEED HELP WITH HTML
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started