随机化背景图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了随机化背景图像相关的知识,希望对你有一定的参考价值。

Set up and array of filenames, which correspond to the file names of the images you are trying to randomize.
  1. <?php
  2. $bg = array('bg-01.jpg', 'bg-02.jpg', 'bg-03.jpg', 'bg-04.jpg', 'bg-05.jpg', 'bg-06.jpg', 'bg-07.jpg' ); // array of filenames
  3.  
  4. $i = rand(0, count($bg)-1); // generate random number size of the array
  5. $selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
  6. ?>
  7.  
  8. <style type="text/css">
  9. <!--
  10. body{
  11. background: url(images/<?php echo $selectedBg; ?>) no-repeat;
  12. }
  13. -->
  14. </style>

以上是关于随机化背景图像的主要内容,如果未能解决你的问题,请参考以下文章

文本作为 CSS 的背景图像

随机化 Firebase 存储中的图像

UITableviewCell 中的随机背景图像

HTML代码片段

HTML代码片段

来自 FragmentActivity 的片段在某些设备上不显示背景图像