网站文本的随机字体?

发布于 2024-11-07 09:59:32 字数 61 浏览 0 评论 0原文

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

I've seen lots of methods for generating random font colours, but how would I go about using a random font from a list of fonts (or just totally random) for a section of text on my website?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

下雨或天晴 2024-11-14 09:59:32

您可以像这样从 PHP 列表中获取随机条目:

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

然后在您想要覆盖该类的任意位置回显 $randomFont 。也许在文档中内联的

You can get a random entry from a list in PHP like this:

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

and then just echo $randomFont wherever you want to override the class. Perhaps in a <style> tag inline in your document

时光瘦了 2024-11-14 09:59:32

创建字体名称数组。

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

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)]

Create an array of font names.

Then when you are setting the color of the text:

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

Here is a fiddle: http://jsfiddle.net/maniator/EJAmv/

And you can do the same for fonts: 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)]
赴月观长安 2024-11-14 09:59:32

试试这个:

<?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>

Try this:

<?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>
罪歌 2024-11-14 09:59:32

这适用于我的网页,我认为这很简单:

<?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>

This works on my Webpage, and I Think it's easy:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文