Get Started with HTML
You can use Spacha with HTML
Prepare
Create
sample-spc
directorymkdir -p sample-spc
Download
spacha.min.js
and place it injs/
directoryPrepare
index.html
index.html<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spacha Sample</title>
</head>
<body>
</body>
</html>Make sure the file structure be like this.
sample-spc
├── index.html
└── js
└── spacha.min.js
1 directory, 2 files
Setup Spacha
- HTML
- Canvas
In this section, we'll create Spacha that build with HTML like this (you can't export as image).
Add
div
tag.index.html...
<body>
<div id="spc-div"></div>
</body>
...Load
spacha.min.js
.index.html...
<body>
<div id="spc-div"></div>
<script src="js/spacha.min.js"></script>
</body>
...Load
spc-div
for Spacha.index.html...
<body>
<div id="spc-div"></div>
<script src="js/spacha.min.js"></script>
<script>
var spc = document.getElementById("spc-div");
new Spacha(spc);
</script>
</body>
...Open HTML on your browser, then you can see that Spacha has build (price will be change each time you reload it).
You can specify detail options.
index.html...
<body>
<div id="spc-div"></div>
<script src="js/spacha.min.js"></script>
<script>
var spc = document.getElementById("spc-div");
new Spacha(spc, {
message: "Hello, Spacha!",
price: 2000,
user: {
name: "Spacha User"
}
});
</script>
</body>
...
Entire of index.html
should be like this.
index.html
should be like this.index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spacha Sample</title>
</head>
<body>
<div id="spc-div"></div>
<script src="js/spacha.min.js"></script>
<script>
var spc = document.getElementById("spc-div");
new Spacha(spc, {
message: "Hello, Spacha!",
price: 2000,
user: {
name: "Spacha User"
}
});
</script>
</body>
</html>
In this section, we'll create Spacha that build with Canvas like this.
Add Canvas tag.
index.html...
<body>
<canvas width="400" id="canvas"></canvas>
</body>
...Load
spacha.min.js
.index.html...
<body>
<canvas width="400" id="canvas"></canvas>
<script src="js/spacha.min.js"></script>
</body>
...Load
Canvas
for SpachaImage.index.html...
<body>
<canvas width="400" id="canvas"></canvas>
<script src="js/spacha.min.js"></script>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
new SpachaImage(ctx);
</script>
</body>
...Open HTML on your browser, then you can see that Spacha has build (price will be change each time you reload it).
You can specify detail options.
index.html...
<body>
<canvas width="400" id="canvas"></canvas>
<script src="js/spacha.min.js"></script>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
new SpachaImage(ctx, {
message: "Hello, Spacha!",
price: 2000,
user: {
name: "Spacha User"
}
});
</script>
</body>
...
Entire of index.html
should be like this.
index.html
should be like this.index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spacha Sample</title>
</head>
<body>
<canvas width="400" id="canvas"></canvas>
<script src="js/spacha.min.js"></script>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
new SpachaImage(ctx, {
message: "Hello, Spacha!",
price: 2000,
user: {
name: "Spacha User"
}
});
</script>
</body>
</html>
Samples
See samples at here.