This review exercise is built around accessing data contained in various data structures, and then taking that data and writing to the DOM using jQuery.
It builds on concepts from the first checkpoints (Checkpoint-00 through 2) and ties them into DOM-manipulation concepts from Week 2.
Clone down this repository. Your job is to write code in js/script.js
that accomplishes the tasks listed below. Do not modify any other file.
- Populate the Header with Staff Member Names
- For testing purposes,
console.log()
each element in thestaff
array injs/script.js
using a for-loop. - Next, use the jQuery function
$()
to create<span>
tags inside the<header>
that is directly in the<main>
tag. The text of each<span></span>
should be each item in thestaff
array, respectively. - You should have added six
span
s and have one name from thestaff
in each<span>
.
- Populating Content for the First Article
- Create a new paragraph element using
$()
and store it in a variable. Set its text to thetext
property of the first object inarticles
and append it to the<section>
inside of the first<article>
.
> - You'll need to comment out `height: 444px;` in the rule for `articles` in styles/style.css to avoid overflow.
-
In the first
<article>
, set the text of the<h3>
inside<header>
to thetitle
from the first object inarticles
. -
Modify the
byline
property of the firstarticles
by concatenating it with the 1st value instaff
. -
Take the new value of the
byline
property and add it to the text of the<header>
within the first<article>
. -
Add an
editor
property to the first object inarticles
and give it the value of the 2nd item in thestaff
array. -
Create and append a
<span>
inside the<header>
of the first<article>
, where the new<span>
's text is the value of theeditor
property you just created. -
Render the image, from the
body
property of the first object inarticles
, to the<figure>
element in the first<article>
. -
Using a for-loop to populate content for each article
-
Adapt the code you wrote in the previous section to work with a for loop that iterates over the objects in
articles
. -
Hovering the cursor over a paragraph changes its background color to lightGrey. When the mouse exits the paragraph, the color should revert back to its previous value.
-
Store the default background-color value in a variable.
-
Change the background color to light grey when the mouse hovers over the paragraph.
-
Determine the event that corresponds to the mouse exiting the area of a DOM element.
-
Add event listeners to listen for this type of event, and have the background color revert to its default value when this event occurs.
-
Use jQuery animate to have the staff names slide and fade into view. Check out http://api.jquery.com/animate/
-
Add infinite scroll by re-appending the articles when the user scrolls to a certain point near the bottom.
Write a little bit of code, and then test it--work methodically.
use $ in variable names that refer to jQuery objects/collections (this is a recommended convention, and will not have an impact on code function).
var $body = $("body");
Store references to each part of the DOM you need to interact with. Example:
var $paragraphs = $("p");
var $smallestHeaders = $("h6");