html5-import

Images created using `document.currentScript.ownerDocument.createElement` (from within <link> imported HTML) never load

女生的网名这么多〃 提交于 2019-12-24 12:05:21
问题 Here's a function that returns the width of an image, given the image's url: async function getImageWidthByUrl(imgUrl) { const imgEl = document.createElement("img"); let untilImgLoaded = new Promise((resolve, reject) => { imgEl.onload = resolve; imgEl.onerror = reject; }); imgEl.src = imgUrl; await untilImgLoaded; return imgEl.naturalWidth; } It works fine. It also (of course) works if we use new Image() instead of document.createElement("img") . However, the document.createElement("img")

Vanilla web-component structure

我的梦境 提交于 2019-11-28 00:27:04
I am looking into structuring vanilla web-components. I have previously used Polymer and like the fact that you can have the template, styles and JavaScript in one file for your component. I want to achieve this with 'vanilla' web components if possible but can't work out how. I've taken the code from here and added it to a file which I am using as follows: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Component test</title> <link rel="import" href="x-foo-from-template.html"> </head> <body> <x-foo-from

Vanilla web-component structure

大城市里の小女人 提交于 2019-11-26 23:25:15
问题 I am looking into structuring vanilla web-components. I have previously used Polymer and like the fact that you can have the template, styles and JavaScript in one file for your component. I want to achieve this with 'vanilla' web components if possible but can't work out how. I've taken the code from here and added it to a file which I am using as follows: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">