Saturday, May 17, 2014

Random /dynamic Background Image

Using this code we can using random background image.Also using this way we can use other CSS in dynamic way .

<?php
  $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg' ); // we can  insert as many file as we want

  $i = rand(0, count($bg)-1);
  $selectedBg = "$bg[$i]";
?>

background: url(images/<?php echo $selectedBg; ?>) no-repeat;

we can use this as inline css link

<header class="page-header" style="background-image: url('images/<?php echo $selectedBg; ?>');">

Thanks

No comments:

Post a Comment

Total Pageviews