We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi folks
I made a little sound toy/game for the homepage of my website, which you can see here: http://georgehenryrowe.co.uk/
The canvas is added to the #sketch-holder div on the page. This all fine.
However, for some reason I can't figure out it is also added to every other page of my website as the last bit of HTML, as a canvas called defaultCanvas0. Doing a little bit of reading implied that this might be because sketch.js is being called before the DOM is loaded, but wrapping my sketch.js in
document.addEventListener("DOMContentLoaded", function (event)
\\ sketch.js
});
just causes it to not work. Anyone had a similar issue?
Many thanks
George
Answers
Oh I also tried using jQuery to test whether the sketch-holder div exists.
For some reason, without this I get a massive defaultCanvas0 which doesn't run on every page, with it I get a small canvas which runs on every page :/
Figured it out. I was loading p5js in my header, so it was on every page. I didn't realise that it would create a canvas in instance mode, even if you don't call createCanvas().
So now I am only loading p5 on the homepage, and no problem :)
@georgehenryrowe thanks for sharing your solution!