例如
并把这个作为背景,在上边可以放置我们设置的标题和小图片
两种试一下,微调一下就行了
<!DOCTYPE html>
<html>
<head>
<style>
.cities {
background-color:black;
color:white;
margin:20px;
padding:20px;
}
.circle-1,
.circle-2 {
width: 150px;
height: 150px;
border-radius: 50%;
position: relative;
}
.circle-1 {
background-color: red;
}
.circle-2 {
background-color: green;
top: -75px;
left: 25px;
}
canvas {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="circle-1"></div><div class="circle-2"></div>
</body><script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
// 绘制红色圆形
ctx.beginPath();
ctx.arc(100, 100, 75, 0, Math.PI * 2);
ctx.fillStyle = "red";
ctx.fill();
// 绘制绿色圆形并实现重叠效果
ctx.beginPath();
ctx.arc(150, 150, 75, 0, Math.PI * 2);
ctx.fillStyle = "green";
ctx.globalCompositeOperation = "source-in";
ctx.fill();
</script>
</html>
2 回答862 阅读✓ 已解决
4 回答956 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
2 回答1k 阅读✓ 已解决
2 回答2.6k 阅读
1 回答1k 阅读✓ 已解决
2 回答879 阅读✓ 已解决
index.html
demo1.js