Last active
April 14, 2022 06:55
-
-
Save AlanD20/83283ff6595c2e61c9c1200bfb99f3ee to your computer and use it in GitHub Desktop.
HTML codes
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Test</title> | |
<style> | |
button { | |
background: crimson; | |
color: white; | |
padding: 6px auto; | |
margin: 10px 35%; | |
font-size: 14px; | |
font-weight: bold; | |
} | |
.popwrap { | |
background: rgba(0, 0, 0, 0.5); | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
display: none; | |
} | |
.pop { | |
text-align: center; | |
width: 100%; | |
max-width: 300px; | |
margin: 10% auto; | |
padding: 20px; | |
background: white; | |
position: relative; | |
font-size: 16px; | |
font-family: arial; | |
} | |
.pop a { | |
text-decoration: none; | |
color: white; | |
background: crimson; | |
padding: 4px 8px; | |
font-weight: bold; | |
font-size: 20px; | |
} | |
.pop .close { | |
color: white; | |
position: absolute; | |
top: 5px; | |
right: 8px; | |
background: black; | |
font-size: 25px; | |
font-weight: bold; | |
display: inline; | |
padding: 2px 7px; | |
} | |
.pop .close:hover { | |
color: crimson; | |
cursor: pointer; | |
} | |
</style> | |
</head> | |
<body> | |
<button>Click me</button> | |
<div class="popwrap"> | |
<div class="pop"> | |
<div class="close">X</div> | |
<div class="content"> | |
<h2>WELCOME</h2> | |
<p>Subscribe to me!!!</p> | |
<a href="https://twitter.com/AlanD_2011" target="_blank" | |
>Click on me for Twitter!</a | |
> | |
</div> | |
</div> | |
</div> | |
<script> | |
const btn = document.querySelector("button"); | |
const pop = document.querySelector(".popwrap"); | |
const cls = document.querySelector(".popwrap .pop .close"); | |
btn.addEventListener("click", () => { | |
pop.style.display = "block"; | |
}); | |
cls.addEventListener("click", () => { | |
pop.style.display = "none"; | |
}); | |
pop.addEventListener("click", () => { | |
pop.style.display = "none"; | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
<html> | |
<head> | |
<style> | |
*, *::after, *::before{ | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
.main { | |
background-image: url(//unsplash.it/300/400); | |
clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); | |
background-repeat: no-repeat; | |
background-color: white; | |
background-blend-mode: luminosity; | |
width: 300px; | |
height: 400px; | |
position: relative; | |
transition: background 200ms cubic-bezier(0.06, 0.17, 0.92, 1.03); | |
} | |
.main::before{ | |
content: 'Hello Sadq'; | |
color: white; | |
position: absolute; | |
text-align: center; | |
top: 0px; | |
left: 0px; | |
width: 100%; | |
height: 100%; | |
padding: 50% 1em; | |
background-color: black; | |
z-index: 5; | |
opacity: 0; | |
transition: opacity 300ms cubic-bezier(0.06, 0.17, 0.92, 1.03); | |
} | |
.main:hover{ | |
background-image: url(https://loremflickr.com/300/400); | |
width: 300px; | |
height: 400px; | |
background-repeat: no-repeat; | |
transition: background 200ms cubic-bezier(0.06, 0.17, 0.92, 1.03); | |
} | |
.main:hover::before{ | |
opacity: 0.5; | |
cursor: pointer; | |
transition: opacity 300ms cubic-bezier(0.06, 0.17, 0.92, 1.03); | |
} | |
</style> | |
</head> | |
<body> | |
<div class="main"></div> | |
</body> | |
</html> |
This file contains hidden or 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
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Todos</title> | |
<script | |
src="https://kit.fontawesome.com/692be75aee.js" | |
crossorigin="anonymous" | |
></script> | |
<link | |
rel="stylesheet" | |
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" | |
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" | |
crossorigin="anonymous" | |
/> | |
<style> | |
body { | |
background: #352f5b; | |
} | |
.container { | |
max-width: 400px; | |
} | |
input[type="text"], | |
input[type="text"]:focus { | |
color: #fff; | |
border: none; | |
background: rgba(0, 0, 0, 0.2); | |
max-width: 400px; | |
} | |
.todos li { | |
background: #423a6f; | |
} | |
.delete { | |
cursor: pointer; | |
} | |
.filtered { | |
display: none !important; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<header class="text-center text-light my-4"> | |
<h1 class="mb-4">Todo List</h1> | |
<form class="search"> | |
<input | |
type="text" | |
name="search" | |
class="form-control m-auto" | |
placeholder="Search..." | |
/> | |
</form> | |
</header> | |
<ul class="list-group todos mx-auto text-light"> | |
<li | |
class="list-group-item d-flex justify-content-between align-item-center" | |
> | |
<span>Kurdistan</span> | |
<i class="far fa-trash-alt delete"></i> | |
</li> | |
<li | |
class="list-group-item d-flex justify-content-between align-item-center" | |
> | |
<span>Sulaymaniyah</span> | |
<i class="far fa-trash-alt delete"></i> | |
</li> | |
<li | |
class="list-group-item d-flex justify-content-between align-item-center" | |
> | |
<span>Erbil</span> | |
<i class="far fa-trash-alt delete"></i> | |
</li> | |
</ul> | |
<form class="add text-center my-4"> | |
<label class="text-light">Add a new todo...</label> | |
<input type="text" name="add" class="form-control m-auto" /> | |
</form> | |
</div> | |
<script> | |
const addFrom = document.querySelector(".add"); //text input for new todo item. | |
const list = document.querySelector(".todos"); //grab the ul list | |
const searchBar = document.querySelector(".search input"); | |
//function to generate the template. | |
const newItem = (item) => { | |
const code = `<li | |
class="list-group-item d-flex justify-content-between align-item-center"> | |
<span>${item}</span> | |
<i class="far fa-trash-alt delete"></i> | |
</li>`; | |
list.innerHTML += code; //appending the code. | |
}; | |
//add todos | |
addFrom.addEventListener("submit", (e) => { | |
e.preventDefault(); | |
const todo = addFrom.add.value.trim(); //trim it will remove all the spaces before and after the string. | |
if (todo.length) { | |
//returns true or false. | |
newItem(todo); | |
} | |
addFrom.reset(); //clears out everything inside the form | |
}); | |
//delete todos | |
list.addEventListener("click", (e) => { | |
if (e.target.classList.contains("delete")) { | |
e.target.parentElement.remove(); //deleting the parent | |
} | |
}); | |
const filtertodos = (term) => { | |
Array.from(list.children) | |
.filter((item) => !item.textContent.toLowerCase().includes(term)) //it will return the texts that does not contain the searching letters because we want to filter out those that we dont need to show it. | |
.forEach((todo) => todo.classList.add("filtered")); //adding each of them a filtered class | |
//this one is opposite of the previous code. | |
Array.from(list.children) | |
.filter((item) => item.textContent.toLowerCase().includes(term)) | |
.forEach((item) => item.classList.remove("filtered")); | |
}; | |
searchBar.addEventListener("keyup", (e) => { | |
const term = searchBar.value.trim().toLowerCase(); | |
filtertodos(term); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" | |
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
<title>Accu Weather</title> | |
<style> | |
body { | |
background: #eeedec; | |
letter-spacing: 0.2em; | |
font-size: 0.8em; | |
} | |
.container { | |
max-width: 400px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container my-5 mx-auto"> | |
<h1 class="text-muted text-center my-4">Accu Weather</h1> | |
<form class="change-location my-4 text-center text-muted"> | |
<label for="city">Enter a location for weather information</label> | |
<input type="text" name="city" class="form-control p-4"> | |
</form> | |
<div class="card shadow-lg rounded "> | |
<!--here is d-none--> | |
<img src="https://via.placeholder.com/400x300" class="time card-img-top"> | |
<div class="icon bg-light mx-auto text-center"> | |
<!-- icon here later --> | |
</div> | |
<div class="text-muted text-uppercase text-center details"> | |
<h5 class="my-3">City name</h5> | |
<div class="my-3">Weather condition</div> | |
<div class="display-4 my-4"> | |
<span>temp</span> | |
<span>°C</span> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script> | |
const key = "fJ6w6OZc2JK8CgA9Jw2XyMT1OlOJ7Gts"; | |
const form = document.querySelector("form"); | |
const card = document.querySelector(".card"); | |
const details = document.querySelector(".details"); | |
const getCity = async city => { | |
const base = "http://dataservice.accuweather.com/locations/v1/cities/search"; | |
const query = `?apikey=${key}&q=${city}`; | |
const response = await fetch(base + query); | |
const data = await response.json(); | |
return data[0]; | |
}; | |
const getWeather = async id => { | |
const base = "http://dataservice.accuweather.com/currentconditions/v1/"; | |
const query = `${id}?apikey=${key}`; | |
const response = await fetch(base + query); | |
const data = await response.json(); | |
return data[0]; | |
}; | |
form.addEventListener("submit", e => { | |
e.preventDefault(); | |
const city = form.city.value.trim(); | |
update(city).then(data => updateGUI(data)); | |
form.reset(); | |
}); | |
const update = async (city) => { | |
const ct = await getCity(city); | |
const wth = await getWeather(ct.Key); | |
return { | |
City: ct, | |
Weather: wth | |
}; | |
}; | |
const updateGUI = data => { | |
const { City, Weather } = data; | |
details.innerHTML = ` | |
<h5 class="my-3">${City.EnglishName}</h5> | |
<div class="my-3">${Weather.WeatherText}</div><div class="display-4 my-4"> | |
<span>${Weather.Temperature.Metric.Value}</span> | |
<span>°C</span>`; | |
if (card.classList.contains('d-none')) { | |
card.classList.remove('d-none'); | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment