You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.3 KiB
59 lines
2.3 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Picsum photos</title>
|
|
<link rel="stylesheet" href="css/bootstrap.css">
|
|
<style>
|
|
.card {
|
|
box-shadow: 0 20px 20px rgba(0,0,0,0.5);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container text-center">
|
|
<h1 class="display-2">Random Picsum photos</h1>
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card mt-5">
|
|
<div class="card-body">
|
|
<img src="" alt="Náhodný Obrázek" id="randomImg" class="img-fluid">
|
|
<br>
|
|
<button id="nextImg" class="mt-2 btn btn-primary">Další obrázek</button>
|
|
<br>
|
|
<a id="downloadImg" class="mt-2 btn btn-outline-primary"download> Stáhnout náhodný obrázek</a>
|
|
<br>
|
|
<input type="number" name="widthIn" id="widthIn"
|
|
placeholder="Šířka" class="form-control" value="500">
|
|
<input type="number" name="heightIn" id="heightIn"
|
|
placeholder="Výška" class="form-control" value="500">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const randomImg = document.getElementById("randomImg")
|
|
const nextImgBtn = document.getElementById("nextImg")
|
|
const widthIn = document.getElementById("widthIn")
|
|
const heightIn = document.getElementById("heightIn")
|
|
const downloadImg = document.getElementById("downloadImg")
|
|
|
|
function getRandomImg(){
|
|
// AltGR + ý = ` (na české klávesnici)
|
|
let width = widthIn.value;
|
|
let height = heightIn.value;
|
|
let newImgUrl = `https://picsum.photos/${width}/${height}?random=${Math.random()}`
|
|
randomImg.src = newImgUrl
|
|
randomImg.onload = function() {
|
|
downloadImg.href = randomImg.src;
|
|
}
|
|
console.log(newImgUrl)
|
|
}
|
|
nextImgBtn.addEventListener("click",getRandomImg)
|
|
getRandomImg()
|
|
</script>
|
|
<script src="js/bootstrap.bundle.js"></script>
|
|
</body>
|
|
</html>
|