Auto commit

上级 d7e9f69e
<template> <template>
<canvas ref="canvas" /> <!-- 创建一个canvas标签,并使用ref属性引用 --> <canvas ref="canvas" />
</template> </template>
<script> <script>
export default { export default {
mounted() { mounted() {
const canvas = this.$refs.canvas; // 获取canvas标签的引用 const canvas = this.$refs.canvas;
const ctx = canvas.getContext("2d"); // 获取canvas上下文 const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth; // 设置canvas的宽度等于窗口的宽度 canvas.width = window.innerWidth;
canvas.height = window.innerHeight; // 设置canvas的高度等于窗口的高度 canvas.height = window.innerHeight;
ctx.fillStyle = "black"; // 设置canvas的填充颜色为黑色 ctx.fillStyle = "black";
ctx.fillRect(0, 0, canvas.width, canvas.height); // 以黑色填充整个canvas ctx.fillRect(0, 0, canvas.width, canvas.height);
let count = 0; // 定义一个计数器 let count = 0;
const render = () => { // 定义一个渲染函数 const render = () => {
count++; // 计数器自增 count += 5;
ctx.fillStyle = `hsl(${count % 360}, 100%, 50%)`; // 根据计数器的值给canvas设置渐变色 ctx.fillStyle = `hsl(${count % 360}, 100%, 50%)`;
ctx.font = "bold 200px sans-serif"; // 设置canvas文字的样式 ctx.font = "bold 200px sans-serif";
ctx.textAlign = "center"; // 设置canvas文字的水平对齐方式为居中 ctx.textAlign = "center";
ctx.textBaseline = "middle"; // 设置canvas文字的垂直对齐方式为居中 ctx.textBaseline = "middle";
ctx.fillText("CSDN", canvas.width / 2, canvas.height / 2); // 在canvas中央绘制文字 ctx.fillText("CSDN", canvas.width / 2, canvas.height / 2);
requestAnimationFrame(render); // 不断地重绘canvas requestAnimationFrame(render);
}; };
render(); // 调用渲染函数
render();
}, },
}; };
</script> </script>
<style> <style>
/* 将 canvas 的定位设置为 fixed,使其始终覆盖整个窗口 */
canvas { canvas {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; /* 将 canvas 的宽度设置为 100% */ width: 100%;
height: 100%; /* 将 canvas 的高度设置为 100% */ height: 100%;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册