简体   繁体   中英

Typed.js random word

Is there a way to get a random word with Typed.js ?

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

Output should be one of these words. (Lorem / Ipsum / Dolor)

You could use Math.Random() to select a random item in the array

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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