简体   繁体   English

Typed.js随机词

[英]Typed.js random word

Is there a way to get a random word with Typed.js ? 有没有办法用Typed.js得到一个随机单词?

$(function(){
  $(".element").typed({
    strings: ["Lorem", "Ipsum", "Dolor"],
    typeSpeed: 0
  });
});

Output should be one of these words. 输出应该是这些单词之一。 (Lorem / Ipsum / Dolor) (Lorem / Ipsum / Dolor)

You could use Math.Random() to select a random item in the array 您可以使用Math.Random()在数组中选择一个随机项

like: 喜欢:

$(function(){
    var stringArray = ["Lorem", "Ipsum", "Dolor"];
    var randomNumber = Math.round(Math.random() * (stringArray.length - 1)); //random number between 0 and stringArray length
    $(".element").typed({
        strings: [stringArray[randomNumber]],
        typeSpeed: 0
    });
});

The feature is already built-in. 该功能已内置。 Just add, shuffle: true, 只需添加, shuffle: true,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM