Skip to content

Commit 4bf738d

Browse files
committed
css fixes
1 parent 791d370 commit 4bf738d

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

each day build day!/Day 29/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<input type="search" name="search box" class="search__input" placeholder="Search an Article">
1717
<button class="btn cta" onclick="getTheArticle()" value=""> search </button>
1818
</div>
19+
20+
<div class="searchResults"></div>
1921
<script src="main.js"></script>
2022
</body>
2123
</html>

each day build day!/Day 29/main.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,40 @@ function getTheArticle(){
1313
isLoding = true;
1414
fetch(searchArticleUrl)
1515
.then(res=>res.json())
16-
.then(data=>console.log(data))
16+
.then(data=>{
17+
console.log(data)
18+
const articles = data.query.search;
19+
displayArticles(articles);
20+
})
1721
.then(err=>console.log(err))
1822
isLoding = false;
1923
//reset the search bar
2024
}
2125

2226
function displayArticles(articles){
2327

28+
// Store a reference to `.searchResults`
29+
const searchResults = document.querySelector('.searchResults');
30+
// Remove all child elements
31+
searchResults.innerHTML = '';
32+
33+
// Loop over results array
34+
articles.forEach(article => {
35+
const url = encodeURI(`https://en.wikipedia.org/wiki/${article.title}`);
36+
37+
searchResults.insertAdjacentHTML('beforeend',
38+
`<div class="resultItem">
39+
<h3 class="resultItem-title">
40+
<a href="${url}" target="_blank" rel="noopener">${article.title}</a>
41+
</h3>
42+
<span class="resultItem-snippet">${article.snippet}</span><br>
43+
<a href="${url}" class="resultItem-link" target="_blank" rel="noopener">${url}</a>
44+
</div>`
45+
);
46+
});
2447
}
2548

49+
2650
function displayLoadingSpinner(){
2751

2852
if(isLoding)console.log('display spinner')

each day build day!/Day 29/style.css

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ html{
1212

1313

1414
.search{
15-
margin: 10% auto;
15+
margin: 1rem auto;
1616
height: 20rem;
1717
width: 20rem;
1818
display:flex;
@@ -22,6 +22,23 @@ html{
2222
background-color: rgb(122, 121, 118);
2323
}
2424

25+
.searchResults{
26+
margin: 5rem 40rem ;
27+
width: 55rem;
28+
text-align: left;
29+
font-size: 1.2rem;
30+
}
31+
32+
.resultItem {
33+
opacity: 0;
34+
margin-bottom: 20px;
35+
animation: show 0.5s forwards ease-in-out;
36+
color: white;
37+
border-radius: 2px;
38+
padding: 10px;
39+
width: 100%;
40+
}
41+
2542
a{
2643
height: 2rem;
2744
background-color: aliceblue;
@@ -34,4 +51,16 @@ a{
3451

3552
.search__input{
3653
background-color: aliceblue;
37-
}
54+
}
55+
56+
@keyframes show {
57+
0% {
58+
opacity: 0;
59+
transform: translateY(100px);
60+
}
61+
62+
100% {
63+
opacity: 1;
64+
transform: translateY(0);
65+
}
66+
}

0 commit comments

Comments
 (0)