let backgrounds = [
'#eee',
'#000',
'green'
];
document.body.style.background = backgrounds[Math.floor(Math.random()*backgrounds.length)];
JavaScript:let backgrounds = [ '#eee', '#000', 'green' ]; document.body.style.background = backgrounds[Math.floor(Math.random()*backgrounds.length)];
Bu kodu sayfanıza ekleyin, '#eee' olan tırnakların içine resim urlsini yazın.
iyi forumlar
Hocam verdiğiniz kod sadece renklerde çalışıyor resim URL girdiğimizde çalışmıyor.
JavaScript:let backgrounds = [ 'https://i.picsum.photos/id/521/4000/1800.jpg', 'https://i.picsum.photos/id/321/4000/1800.jpg', 'https://i.picsum.photos/id/122/4000/1800.jpg' ]; document.body.style.backgroundImage = "url('"+backgrounds[Math.floor(Math.random()*backgrounds.length)] + "')";
Bu kod işinizi görecektir.
https://jsfiddle.net/BerkPW/dLa1w3ct/1/ (Demo)
Gönderi otomatik olarak birleştirildi:
backgroundImage 'e renk kodu veremezsin maalesef.
let backgrounds = [
'https://i.picsum.photos/id/521/4000/1800.jpg',
'https://i.picsum.photos/id/321/4000/1800.jpg',
'https://i.picsum.photos/id/122/4000/1800.jpg'
];
document.body.style.backgroundImage = "url('"+backgrounds[Math.floor(Math.random()*backgrounds.length)] + "')";
backgroundImage 'e renk kodu veremezsin maalesef.JavaScript:let backgrounds = [ '#eee', '#000', 'green' ]; document.body.style.backgroundImage = backgrounds[Math.floor(Math.random()*backgrounds.length)];
Şöyle deneyebilir misiniz?
JavaScript:let backgrounds = [ 'https://i.picsum.photos/id/521/4000/1800.jpg', 'https://i.picsum.photos/id/321/4000/1800.jpg', 'https://i.picsum.photos/id/122/4000/1800.jpg' ]; document.body.style.backgroundImage = "url('"+backgrounds[Math.floor(Math.random()*backgrounds.length)] + "')";
Bu kod işinizi görecektir.
https://jsfiddle.net/BerkPW/dLa1w3ct/1/ (Demo)
Gönderi otomatik olarak birleştirildi:
backgroundImage 'e renk kodu veremezsin maalesef.
(onlar örnek.)JavaScript:let backgrounds = [ 'https://i.picsum.photos/id/521/4000/1800.jpg', 'https://i.picsum.photos/id/321/4000/1800.jpg', 'https://i.picsum.photos/id/122/4000/1800.jpg' ]; document.body.style.backgroundImage = "url('"+backgrounds[Math.floor(Math.random()*backgrounds.length)] + "')";
Bu kod işinizi görecektir.
https://jsfiddle.net/BerkPW/dLa1w3ct/1/ (Demo)
Gönderi otomatik olarak birleştirildi:
backgroundImage 'e renk kodu veremezsin maalesef.
(onlar örnek.)