Hi all,
I would like to have a clickable link in my canvas. However the help page for createA doesn’t let you know how to draw it at, say, (200, 400) on the canvas. How do I do this? I tried translate, but it doesn’t work.
function setup() {
createCanvas(windowWidth, windowHeight);
createA('http://p5js.org/', 'this is a link');
}
let link;
function setup() {
createCanvas(400, 400);
link = createA('http://p5js.org/', 'this is a link','_blank');
link.position(10,20);
}
function draw() {
background(220);
}
works to move the dom element over the canvas and not below
if you have HTML elements above the canvas the position thing gets tricky but still possible.
Lovely! Thank you kll Do you know where I would find this in a reference page (other dot options for dom elements)? For example, I’d like to know how to change the text’s colour, size and font as well.
If you have access to the stylesheet it might be easier to use that for styling. If the link is inside the canvas, you could probably target it like this:
let atext = "test";
let div;
function setup() {
createCanvas(400, 400);
div = createDiv(atext);
div.position(100,100);
div.style('font-family','verdana');
div.style('font-size',100+'px');
}
function draw() {
background(220);
}
The key concept there is that p5.dom is manipulating the DOM, so a lot of the documentation for what you can do is in the HTML and CSS3 spec, as @kll linked to w3schools – you are rewriting objects according to those specs in a way that creates html elements just as if they had originally been part of the page, so anything that would be valid CSS3 will be a valid style argument to attach to one of those elements – the p5.DOM library doesn’t inspect the tokens or contain any special logic for rendering them, JavaScript just passes them on to the browser. ‘font-family’ is one of the things that you can pass – but there are probably over 200 others. https://www.w3schools.com/cssref/