当前位置:网站首页>Achieve random labels, font size, color random display
Achieve random labels, font size, color random display
2022-04-21 13:34:00 【Little R】
Recently wrote graduation , Want to achieve the effect shown in the figure below ( Here is an example from the student's personal blog ):

As shown in the figure above , Random label , The font color is random , The font size is random .
Here's my implementation code .
<template></template> The code in :
<router-link
v-for="item in tagList"
:key="item.id"
:to="`/tag/${item.id}`"
:style="{ color: getColor(), fontSize: getSize() }"
>{
{
item.text }}
</router-link>
<script>/<script> The code in :
<script>
export default {
data() {
return {
tagList: [
{
id: 1,
text: " front end ",
},
{
id: 2,
text: "JavaScript",
},
{
id: 3,
text: "Node.js",
},
{
id: 4,
text: "Vue",
},
{
id: 5,
text: "webpack",
},
{
id: 6,
text: " Personal summary ",
},
{
id: 7,
text: "React",
},
{
id: 8,
text: "TypeScript",
},
],
};
},
methods: {
/* Random font color */
getColor() {
var colorArr = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f".split(",");
var color = "#";
for (var i = 0; i < 6; i++) {
color += colorArr[Math.floor(Math.random() * 16)];
}
return color;
},
/* Random font size */
getSize() {
return Math.floor(Math.random() * 10 + 16) + "px";
},
},
mounted() {
},
};
</script>
css The code is not pasted here, ha ha , Just adjust the spacing , Get rid of a The underline of the label and so on .
As above, we can achieve .
Be careful : Here I am vue Written in the project , So it's in vue How to implement in .
If you want to use native js stay html Implementation in file , You can write a function , And pass in the tag array parameter , Traverse every item in the array , Put the font color 、 The size and value are shown in a label , And put a The labels are spliced into html, Finally, get where you want to insert the value .innerHTML = Put together html, that will do . You can try .
版权声明
本文为[Little R]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211333066098.html
边栏推荐
- 53W words! Ali's first system performance optimization guide is so fragrant that it can be called the optimal solution of performance optimization
- Installing and configuring canal
- Getting started with Xcode cloud: pull request (PR) workflow
- 科技巨头竞相入场,谁能成为元宇宙“头号玩家”?
- Flink相关API开发及运行架构和实现原理详解
- Could not load dynamic library ‘libcusolver. so. 11‘
- 一份很棒的外设驱动库!(基于STM32F4)
- metasploit渗透
- 运动耳机什么样的舒服、运动健身耳机推荐
- Buuctf [Chapter 3 Advanced Web] logic vulnerability
猜你喜欢

国际物流集运系统源码,海外仓储跨境转运系统源码

Last online class can be "distracted" by AI analysis. Intel's emotional detection AI is on fire

Idea automatically generates unit test classes

北京大学ACM Problems 1009:Edge Detection

大才能否小用?OceanBase一体化场景测试

科技巨头竞相入场,谁能成为元宇宙“头号玩家”?

Upgrade the jdbc driver to version 8.0.28 and connect the pit record of MySQL

Tailwind core concept - responsive design

海口等保测评公司有几家?具体在哪里?哪里可以查到?

leetcode:513. 找树左下角的值【简单bfs找每层第一个】
随机推荐
BUUCTF [第三章 web进阶]逻辑漏洞
boost asio的work作用
Leetcode: countless denominations of coins get the option of amount (DP)
被迫选择了到了外包公司
安装和配置Canal
S: Unit gain compensation
What kind of comfortable sports earphones are recommended
做自媒体、短视频,不要再相信那些互关、互赞了
必选项输入内容后红色星号消失
完成数亿元融资后,毫末智行计划超百城落地城市智能驾驶产品
Required. The red asterisk disappears after entering the content
版图设计的技巧
u盘数据丢失了怎么恢复?u盘数据恢复,2个方案完成
Baidu map development custom information window openinfowindow style
no server suitable for synchronization found
Underlying principle of high concurrent IO
如何在Centos下卸载OpenJDK,安装Oracle JDK
Buuctf [Chapter 3 Advanced Web] logic vulnerability
Flink相关API开发及运行架构和实现原理详解
What is federal learning?