svg 是矢量图。使用svg画的图片,不会怎么放大,都不失真 1: svg 可以通过 img标签加载 2: svg 可以作为字体图标 3: svg 可以用在大屏可视化上 做各种标记点。
开发实例代码如下
// user.svg
<svg verison="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
stroke="#000">
<circle cx="12" cy="12" r="10" fill="yellow"/>
</svg>
// index.js
import user from'./user.svg';
console.log('index.js run');
console.log(user)
const div = document.createElement("div");
div.style.width = '300px';
div.style.height = '300px';
div.style.border = '3px solid red';
// svg 作为背景图片
div.style.background = `url(${user})`;
var body = document.querySelector('body');
body.appendChild(div)
const img = document.createEle