Reflesh yapıldıgında değişen resim
3
●982
- 24-02-2010, 15:24:51Merhabalar sayfa her yenilendiğinde değişen bir background yapmak istiyorum resımler random olabilir belirli bir sıradada değişebilir sabahtan beri arıyorum ama bulamadım tam olarak yardımcı olursanız sevinirim...
- 24-02-2010, 16:58:15anladığım kadarı ile bir şeyler yapmaya çalıştım inşallah işine yarar
aşağıdaki kodları css ne ekle
body { background-attachment : fixed; background-position : center center; background-repeat : no-repeat; margin : 0px; background-color : #EEEEEE; }aşağıdaki kodları da <head> tagından sonraya ekle
<script> function changecss(theClass, element, value) { var cssRules; if (document.all) { cssRules = 'rules'; } else if (document.getElementById) { cssRules = 'cssRules'; } var added = false; for (var S = 0; S < document.styleSheets.length; S++) { for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) { if (document.styleSheets[S][cssRules][R].selectorText == theClass) { if(document.styleSheets[S][cssRules][R].style[element]) { document.styleSheets[S][cssRules][R].style[element] = value; added = true; break; } } } if(!added){ if(document.styleSheets[S].insertRule) { document.styleSheets[S].insertRule(theClass + ' { ' + element + ': ' + value + '; }',document.styleSheets[S][cssRules].length); } else if (document.styleSheets[S].addRule) { document.styleSheets[S].addRule(theClass, element + ': ' + value + ';'); } } } } function setbackground() { sayi = Math.floor(Math.random() * 100);//kaç tane resim olacaksa sayıyı ona göre değiştir var image = "images/"+sayi+"resim.jpg"; changecss("body", "background-image", "url('" + image + "')"); } </script><body> de
<body onload="setbackground()">
ana dizinde images klsörü oluştur resimleride (örenğin 1resim.jpg, 2resim.jpg)olarak ayarla inşallah işini görüür