init
This commit is contained in:
parent
d4b65b4ecd
commit
cddc95ecc4
10
index.html
10
index.html
@ -4,5 +4,15 @@
|
|||||||
<title>canvas-photo-gallery</title>
|
<title>canvas-photo-gallery</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<canvas height="400" width="600" id="c" style="border: 1px solid #333"</canvas>
|
||||||
|
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
|
||||||
|
<script>
|
||||||
|
var vConsole = new window.VConsole();
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
const s = document.createElement("script");
|
||||||
|
s.src = "./main.js?v=" + Date.now();
|
||||||
|
document.body.appendChild(s);
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
31
main.js
Normal file
31
main.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
console.log("load main.js success!");
|
||||||
|
const canvas = document.getElementById("c");
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
ctx.fillStyle = "#eee";
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(20, 20);
|
||||||
|
ctx.lineTo(200, 50);
|
||||||
|
ctx.strokeStyle = 'blue';
|
||||||
|
ctx.lineWidth = 4;
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
ctx.font = "20px Arial";
|
||||||
|
ctx.fillStyle = "black";
|
||||||
|
ctx.fillText("Canvas", 20, 100);
|
||||||
|
|
||||||
|
requestAnimationFrame(render);
|
||||||
|
}
|
||||||
|
|
||||||
|
render();
|
||||||
|
|
||||||
|
canvas.addEventListener("click", (e) => {
|
||||||
|
const rect = canvas.getBoundingClientRect();
|
||||||
|
const x = e.clientX - rect.left;
|
||||||
|
const y = e.clientY - rect.top;
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user