jQuery plugin for generating multi coloured text which changes colour on hover

前端 未结 2 1990
予麋鹿
予麋鹿 2021-01-28 11:42

I would like to generate multicoloured text for various links, with a random assignment of colours to individual letters, from a pre-specified array of colours, which would chan

2条回答
  •  梦毁少年i
    2021-01-28 12:26

    Ok i whip up an example using jquery.

    first your text

    Multi color me

    then the javascript:

    $(document).ready(function() {
      var test = $("#example").text().split('');
    
        var result = "";
        var i = 0;
        for(i=0; i < test.length; i++) {
            result += ""+test[i]+"";
        }
        $("#example").html(result);      
    });
    
    function getColor() {
        var colList = ['#00FF00', '#FF0000','#0000FF'];
    
        var i = Math.floor((Math.random()*colList.length));
      return colList[i];
    }​
    

    Heres the jsFiddle Example

    Note: i did not do the hover but I guessing you can take it from here :)

提交回复
热议问题