Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Foren / Cotonti / Skins / random logo css

How to?

musashi9
#1 19. Oktober 2012, 11:54

Hello I want to load a random logo in my header but I have no idea how to

This is what I have in my css............

#header {
background: url(../img/logo2.png) no-repeat ;

background-color: #113355;
     width:1000px;
     height:181px;
    height: 278px;
}

and this is from my header.tpl............

<div id="header">
 

</div>

How can I get it to load a random image ?

GHengeveld
#2 19. Oktober 2012, 16:30

Easiest solution is to use JavaScript:

<script type="text/javascript">
$(function() {
  var logos = ["../img/logo1.png", "../img/logo2.png", "../img/logo3.png"];
  $('#header').css('background-image', 'url(' + logos[Math.floor(Math.random()*logos.length)] + ')');
});
</script>

Put it in header.tpl, right before </head>

musashi9
#3 19. Oktober 2012, 16:48

Excelent works like a charm, thanks!

elfrenazo
#4 25. Oktober 2012, 05:49

very good code