Skip to content

Commit

Permalink
Fix: cube window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
luciobenini committed Oct 30, 2021
1 parent 6e1716c commit 7b9af36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pittica/gatsby-plugin-canvas-animations",
"private": false,
"description": "Canvas animations collection for GatsbyJS.",
"version": "2.0.2",
"version": "2.0.3",
"author": {
"name": "Lucio Benini",
"email": "info@pittica.com",
Expand Down
18 changes: 13 additions & 5 deletions src/components/cube.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ export default function Cube({ color, background }) {
canvas.width = canvas.parentNode.clientWidth
canvas.height = canvas.parentNode.clientWidth

window.addEventListener("resize", () => {
canvas.width = canvas.parentNode.clientWidth
canvas.height = canvas.parentNode.clientWidth
window.addEventListener("resize", resize)

draw()

draw()
})
return () => window.removeEventListener("resize", resize)
} else {
canvas.width = 1920
canvas.height = 1080
Expand All @@ -27,6 +26,15 @@ export default function Cube({ color, background }) {
draw()
}, [])

const resize = () => {
const canvas = ref.current

canvas.width = canvas.parentNode.clientWidth
canvas.height = canvas.parentNode.clientHeight

draw()
}

const draw = () => {
const canvas = ref.current

Expand Down

0 comments on commit 7b9af36

Please sign in to comment.