-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcd910e
commit fb00e5a
Showing
3 changed files
with
142 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const searchbox=document.querySelector('.searchbox'); | ||
const searchbtn=document.querySelector('.search-btn'); | ||
const recipecontainer=document.querySelector('.recipe-container'); | ||
|
||
const fetchrecipes= async (query)=>{ | ||
recipecontainer.innerHTML="Fetching recipes" | ||
const data= await fetch(`https://www.themealdb.com/api/json/v1/1/search.php?s=${query}`); | ||
|
||
const response= await data.json(); | ||
recipecontainer.innerHTML=""; | ||
response.meals.forEach(meal => { | ||
// normal for loop bhi lga skte h | ||
const recipediv=document.createElement('div'); | ||
recipediv.classList.add('recipe');// meal islie lere h bcoz hmne foreach loop mei element ka naam meal lia h toh usse acccess krenge sbko | ||
|
||
recipediv.innerHTML=` | ||
<img src="${meal.strMealThumb}"> | ||
<h3>${meal.strMeal}</h3> | ||
<p>${meal.strArea}</p> | ||
<p>${meal.strCategory}</p>` | ||
|
||
recipecontainer.appendChild(recipediv);// container mei jo element create kia h usko append krdia | ||
|
||
|
||
|
||
}); | ||
//console.log(response.meals[0]);// jo pehla meal tha vo access ho gya | ||
|
||
} | ||
|
||
searchbtn.addEventListener('click', (e)=>{ | ||
e.preventDefault();//autosubmit ni hoega , page refresh ni hga button click krne p | ||
const searchinput=searchbox.value.trim(); | ||
fetchrecipes(searchinput); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,83 @@ | ||
*{ | ||
background-color: lightcoral; | ||
} | ||
margin:0; | ||
padding:0; | ||
box-sizing: border-box; | ||
font-family: Verdana, Geneva, Tahoma, sans-serif; | ||
|
||
} | ||
body{ | ||
background-color: #2b1d0f; | ||
color:#fff; | ||
|
||
} | ||
header nav{ | ||
background-color: #212121; | ||
padding: 20px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
z-index: 1;/* jiska z-index zyada hta h vo text upr dikhta h*/ | ||
|
||
} | ||
header nav h1{ | ||
font-size: 26px; | ||
font-weight: 700; | ||
letter-spacing: 1px; | ||
text-transform: uppercase; | ||
} | ||
header nav form{ | ||
display: flex; | ||
justify-content: center; | ||
|
||
} | ||
form input[type="text"]{ | ||
flex-grow: 1; | ||
margin-right: 10px; | ||
|
||
|
||
} | ||
form inut[type="text"],buton[type="submit"]{ | ||
border:none; | ||
font-size: 18px; | ||
padding: 10px; | ||
border-radius:4px ; | ||
} | ||
form button[type="submit"]{ | ||
background-color: #f44336; | ||
color: #fff; | ||
cursor: pointer; | ||
transition: background-color 0.2s ease-in-out;/* taaki jb button pr cursor leke jae toh starting m transition dheere ho and jb cursor hatae tb bhi dheere ho*/ | ||
|
||
|
||
} | ||
form button[type="submit"]:hover{ | ||
background-color:#ff5c5c; | ||
|
||
} | ||
|
||
/*main section css styling*/ | ||
.recipe-container{ | ||
text-align: center; | ||
margin-top: 20px; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
@media screen and (max-width:600px){ | ||
header nav{ | ||
flex-direction: column; | ||
} | ||
header nav form{ | ||
width: 80%; | ||
margin-top: 20px; | ||
|
||
} | ||
|
||
} |