this Anahtar Kellimesi Kullanımı
Örnek
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<style>
body,html{
height: 100%;
}
#kutu{
height: 100px;
width: 100px;
background-color: black;
}
</style>
</head>
<body id="vucud" onload="divOlustur()">
</body>
<script>
function rastgeleRenk(){
const renkler = "0123456789abcdef";
let i;
let sonuc = "";
for(i=0;i<6;i++){
sonuc += renkler[Math.floor(Math.random() * 16)];
}
return sonuc;
}
kacTane = prompt("Kaç tane");
function divOlustur(){
for(let i = 0;i<kacTane;i++){
let rengi = rastgeleRenk();
// alert(rengi);
yeniDiv = document.createElement("div");
yeniDiv.classList.add("kutu");
yeniDiv.style.width = "100px";
yeniDiv.style.height = "100px";
yeniDiv.style.backgroundColor = `#${rengi}`;
yeniDiv.style.position = "absolute";
yeniDiv.style.left = Math.floor(Math.random() * 1920)+"px";
yeniDiv.style.top = Math.floor(Math.random() * 900)+"px";
yeniDiv.addEventListener("click",function(){
this.style.display = "none";
})
document.getElementById("vucud").appendChild(yeniDiv);
}
}
</script>
</html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<style>
body,html{
height: 100%;
}
#kutu{
height: 100px;
width: 100px;
background-color: black;
}
</style>
</head>
<body id="vucud" onload="divOlustur()">
</body>
<script>
function rastgeleRenk(){
const renkler = "0123456789abcdef";
let i;
let sonuc = "";
for(i=0;i<6;i++){
sonuc += renkler[Math.floor(Math.random() * 16)];
}
return sonuc;
}
kacTane = prompt("Kaç tane");
function divOlustur(){
for(let i = 0;i<kacTane;i++){
let rengi = rastgeleRenk();
// alert(rengi);
yeniDiv = document.createElement("div");
yeniDiv.classList.add("kutu");
yeniDiv.style.width = "100px";
yeniDiv.style.height = "100px";
yeniDiv.style.backgroundColor = `#${rengi}`;
yeniDiv.style.position = "absolute";
yeniDiv.style.left = Math.floor(Math.random() * 1920)+"px";
yeniDiv.style.top = Math.floor(Math.random() * 900)+"px";
yeniDiv.addEventListener("click",function(){
this.style.display = "none";
})
document.getElementById("vucud").appendChild(yeniDiv);
}
}
</script>
</html>
Yorumunuzu Ekleyin