some html tweaking

This commit is contained in:
histausse 2022-02-13 00:52:04 +01:00
parent 22787184de
commit a6f89ab707
Signed by: histausse
GPG key ID: 67486F107F62E9E9
2 changed files with 11 additions and 2 deletions

View file

@ -12,7 +12,15 @@
run(); run();
</script> </script>
<canvas id="canvas" height="150" width="150"></canvas> <style>
#circle_canvas{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
<canvas id="circle_canvas" height="150" width="150"></canvas>
</body> </body>
</html> </html>

View file

@ -10,8 +10,9 @@ use circle::CircleShapes;
#[wasm_bindgen(start)] #[wasm_bindgen(start)]
pub fn start() { pub fn start() {
let canvas_id = "circle_canvas";
let document = web_sys::window().unwrap().document().unwrap(); let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id("canvas").unwrap(); let canvas = document.get_element_by_id(canvas_id).unwrap();
let canvas: web_sys::HtmlCanvasElement = canvas let canvas: web_sys::HtmlCanvasElement = canvas
.dyn_into::<web_sys::HtmlCanvasElement>() .dyn_into::<web_sys::HtmlCanvasElement>()
.map_err(|_| ()) .map_err(|_| ())