网站文本的随机字体


random font for website text?

我已经见过很多生成随机字体颜色的方法,但是我将如何使用字体列表中的随机字体(或完全随机)来制作我网站上的一段文本?

你可以从PHP中的列表中获得一个随机条目,如下所示:

$fonts = array("Helvetica", "Arial", "Comic Sans", "Tahoma");
shuffle($fonts);
$randomFont = array_shift($fonts);

然后只需在您想要覆盖类的任何位置回显$randomFont。也许在文档中内联的<style>标签中

创建字体名称数组。

然后,当您设置文本的颜色时:

var array_ofcolors = ['red', 'blue',...]
obj.style.color = 
      array_ofcolors[Math.floor(Math.random()*array_ofcolors.length)]

这是一个小提琴:http://jsfiddle.net/maniator/EJAmv/

你可以对字体做同样的事情:http://jsfiddle.net/maniator/EJAmv/1/

var array_offonts = ["Helvetica", "Arial", "Comic Sans", "Tahoma"]
obj.style.fontFamily = 
      array_offonts[Math.floor(Math.random()*array_offonts.length)]

试试这个:

<?php $font =   array(
      "Arial", 
      "monospace", 
      "Comic Sans MS", 
      "Times", 
      "Lucida Sans", 
      "Verdana", 
      "Helvetica"
    );//insert ^there another Fonts
?>
<a style="font-family: <?php echo $font[rand(0,6)]; ?>;" href="#"><h1>Encrypted array <.../> </h1></a>

这适用于我的网页,我认为这很容易:

<?php 
$font = 
    array(
      "Arial", 
      "monospace", 
      "Comic Sans MS", 
      "Times", 
      "Lucida Sans", 
      "Verdana", 
      "Helvetica"
    );//insert ^there another Fonts
?>
<style> 
 *{ 
   font-family: <?php echo($font[rand(1,7)]); ?>;
  } 
</style>