When I first came into contact with the front-end and looked at the w3cplus part, I felt that the font size of each a tag was completely written (Hi, new guy, no, no way ), today I saw an article about the random color generation method. The core idea is as follows:
An array of the font size to be selected, and then randomly selects one from the array. Setting the font-size for these a tags makes it a success,
[1, 1.2, 1.4, 1.6, 1.8, 2, 2.4] [a] // here a is a randomly generated number, of course, it can only be between 0 and 6, so
var a =Math.floor(Math.random()*7);
The complete code is as follows:
$('.content a').each(function(){ $(this).css('fontSize',[1,1.2,1.4,1.6,1.8,2,2.4][Math.floor(Math.random()*7)]+'em')})
When you enter the page again, you will find that the font size of the tag of this module changes randomly every time you enter the page. Of course, you do not want the font to appear between lines in style, you can also define a group of class names in advance, each class name has a different font size, and then give each a tag random class names,
$(‘.content a’).each(function(){
$(this).attr(‘class’,’leave’+[1,2,3,4,5,6,7][Math.floor(Math.random()*7)])
})
Today, we found that the above two methods did not achieve real random generation, but we just randomly prepared some data and re-compiled the following method:
$('.content a').each(function(){ $(this).css('fontSize',(getFontSize=function(){ fontsize=Math.round(Math.random()*30)/10 if(fontsize<1){ return getFontSize() } return fontsize })()+'em')})
OK, record it so far, in case you forget to use it in the future!