I’m carrying on from my learnings in a recent forum post: howTo reference an attached image in observable slide preso - #4 by aaronkyle
I’m trying to write javascript that will update the image and size in a DIV, and so far I’m not successful writing the image into an empty DIV, I’m only successful when I put the script inside the HTML cell.
This is my sample notebook: https://observablehq.com/d/b1449a98c382035d
Using the array of StoryImages, I’m able to render an attached image in an HTML cell and set the size:
html`<img src="${await storyImages[0].url}" style="height: 100px">`
I’m also able to do something similar in an HTML cell inside a DIV
<DIV id=i2>`${await storyImages[0].img}` </DIV>
But I still can’t figure out how to use javascript to insert the image into a DIV let alone get it sized properly.
const str = "`${await storyImages[0].url}`";
document.getElementById("i0").innerHTML = str;
storyImages = [
{
"index":"1",
"img":FileAttachment("1.jpeg").image(),
"url":FileAttachment("1.jpeg").url()
},
{
"index":"2",
"img":FileAttachment("2.png").image()
},
{
"index":"3",
"img":FileAttachment("3.png").image()
}
]
Thank you,
Bruce