在 chrome 中使用 javascript 设置 SVG 属性(谷歌javascript设置)
25-04-23
2
在本文中,我们将带你了解在chrome中使用javascript设置SVG属性在这篇文章中,我们将为您详细介绍在chrome中使用javascript设置SVG属性的方方面面,并解答谷歌javascr
在本文中,我们将带你了解在 chrome 中使用 javascript 设置 SVG 属性在这篇文章中,我们将为您详细介绍在 chrome 中使用 javascript 设置 SVG 属性 的方方面面,并解答谷歌javascript设置 常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的5 SVG animation tools to make creating SVG much easier、 或 都不是在 iphone 中动画、@vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件、canvas 与 svg 的区别有什么?canvas 和 svg 的区别比较 。
本文目录一览:
在 chrome 中使用 javascript 设置 SVG 属性(谷歌javascript设置) 如何解决在 chrome 中使用 javascript 设置 SVG 属性
也许这是 Chrome (88.0.4324.150) svg 渲染的错误,它似乎只能在此浏览器中重现。但也许我做错了什么?
当我使用 setAttribute 使用 javascript 动态和重复设置填充模式属性时,尽管在检查器中正确显示,但它并不总是可见。如果窗口重绘,例如。通过调整大小,它突然被应用。
为什么属性变化不显示?我是否错过了一些(未记录的)更新调用,或者这只是浏览器错误?
您可以在代码段中看到问题,重复点击填充模式链接。
const doc = document.createElementNS("http://www.w3.org/2000/svg",''svg'');
doc.setAttribute("xmlns","http://www.w3.org/2000/svg");
doc.setAttribute("viewBox","0 0 200 200");
doc.setAttribute("width",200);
doc.setAttribute("height",200);
const polygon = document.createElementNS("http://www.w3.org/2000/svg",''polygon'');
polygon.setAttribute(''stroke'',''black'');
polygon.setAttribute(''stroke-width'',3);
polygon.setAttribute(''fill'',''blue'');
polygon.setAttribute(''fill-rule'',''evenodd'');
polygon.setAttribute(''points'',''150,100,59,129,115,52,147,70'');
doc.appendChild(polygon);
document.getElementById(''dest'').appendChild(doc);
// setting up event handlers
[...document.querySelectorAll(''[data-color]'')].forEach((el) =>
el.addEventListener(
"click",(e) =>
polygon.setAttribute(''fill'',e.target.getAttribute(''data-color''))
)
);
[...document.querySelectorAll(''[data-fill-rule]'')].forEach((el) =>
el.addEventListener(
"click",(e) =>
polygon.setAttribute(''fill-rule'',e.target.getAttribute(''data-fill-rule''))
)
);
<a href="#" data-color="red">set red</a> -
<a href="#" data-color="green">set green</a> -
<a href="#" data-color="blue">set blue</a><br> Problematic,swap multiple: <a href="#" data-fill-rule="evenodd">set evenodd</a>
<a href="#" data-fill-rule="nonzero">set nonzero</a>
<div id="dest"></div>
解决方法
绝对是一个错误。getComputedstyle(polygon).fill-rule
显示正确的 fill-rule
状态,但未应用。
有趣.. MDN 页面没有 浏览器兼容性信息: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
解决方法是使用以下命令移动 多边形内部 SVG:this.closest(''svg'').append(this);
如果您有更复杂的 SVG,您可以使用 insertBefore : https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
将元素“就地”移动之前 本身
移动重绘 具有正确fill-rule
状态的多边形
(但您可能会因动画而产生不必要的副作用)
<b>Click Red color to toggle fill-rule: evenodd/nonzero</b><br>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="50 50 100 100" width="200">
<polygon fill-rule="evenodd" fill="red" points="150,100,59,129,115,52,147,70"
onclick="let fr = this.getAttribute(''fill-rule'')==''evenodd'' ? ''nonzero'' : ''evenodd'';
this.setAttribute(''fill-rule'',fr );
if (event.ctrlKey) this.closest(''svg'').append(this)"></polygon>
</svg>
https://smashinghub.com/5-svg-animation-tools-to-make-creating-svg-much-easier.htm
Scalable vector graphics, SVG for short, has been used more and more in modern web design. They are fun to work with and is especially useful when you want to create special effects on your website. In the past, drawing SVG has been rather cumbersome and restricts their usage. However, with the advent of SVG animation tools, designers and developers can now create SVG at a much faster rate. In article, we will be looking at what is the state of the art for SVG animation tools and what are some of the names you should pay attention to in this area.
Here is the roundup list.
#1: Snap.svg
Snap.svg is not a tool per se but it offers a useful SVG library that allows you to create SVG easily. The good news is that this tool is open and free to use. Try it if you want a faster way to create SVG.
#2: Pencil-Animation
The pencil-animation tool allows you to draw your own garphics, animate them and then export the files as SVG. It is rather old tool that hasn’t seen much update. For designers who like to draw, this is a still a great FREE tool to do your SVG creation.
#3: Adobe Edge Animate
I am sure many of you are similar with this useful tool on adobe edge animate tool. If you already have this, use it to create animated graphics and export them as SVG files. Very easy if you are already familiar with how this software works.
#4: Inkscape
Inkscape is also a old tool that allows designers to create vector graphics easily. It saves all files in SVG by default. Best of all, it is free so do try it if you don’t have this awesome drawing tools in your arsenal of weapons.
#5: SVG.js
This is a light weight library that allows you to create simple SVG. It is really very useful so simple SVG creation and I am so glad I discovered it a couple of months ago. You can now allow this little gem for free so no excuse not to try it.
或 都不是在 iphone 中动画" alt=" 或 都不是在 iphone 中动画">
或 都不是在 iphone 中动画"> 或 都不是在 iphone 中动画 如何解决<object type="image/svg+xml" data="images/loader.svg"> 或 <img src="images/loader.svg" alt="" /> 都不是在 iphone 中动画
我使用了两个标签,但都不适用于 iphone 意味着 svg 在 iphone 中没有动画
<object type = "image/svg+xml" data = "images/loader.svg" >
或
<img src = "images/loader.svg" alt = "" />
@vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件
@vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件
[TOC]
online github
Vue cli 3.0 使用 svg-symbol(svg 雪碧图),整个 https://www.iconfont.cn 的图标库为你所用,加快开发速度.
Vue 脚手架升级 3.0,项目也随之升级。
运行
装包 yarn
or npm i
运行 npm run serve
使用
使用 svg-symbol 引入图标
svg 文件会导入到 HTML 文件中,无需使用两张 png 切换
./src/main.js
引入 import "./icons";
在 ./src/icons/svg
文件夹下的 svg 文件会自动导入项目
https://www.iconfont.cn 下载图标
下载的 svg 图标放在 ./src/icons/svg
文件夹下
为了使用当前环境下的颜色,去掉 svg 的 fill 属性
调用 <svg-icon icon-name="home" class-name="test"></svg-icon>
配置 svg-sprite-loader
// ./vue.config.js
module.exports = {
chainWebpack: config => {
const svgRule = config.module.rule("svg");
svgRule.uses.clear();
svgRule
.use("svg-sprite-loader")
.loader("svg-sprite-loader")
.options({
symbolId: "icon-[name]",
include: ["./src/icons"]
});
}
};
调用当前环境下的颜色
当前环境的颜色改变,图标颜色也会跟着改变
<!--SvgIcon-->
<style>
.svg-icon {
width: 1em;
height: 1em;
fill: currentColor; /*关键*/
overflow: hidden;
}
</style>
props
props
说明
type
iconName
svg 文件名,不要加上后缀
string
className
图标样式类
string
canvas 与 svg 的区别有什么?canvas 和 svg 的区别比较 canvas 与 svg 都是可以在浏览器上创建图形,因此,在 html5 中感觉 canvas 和 svg 很相似,但是实际上 canvas 与 svg 有着根本的区别。下面 php 中文网通过比较 canvas 和 svg 之间的不同来给大家总结了关于 canvas 与 svg 的区别。一起来看一看吧。
在说 canvas 与 svg 的区别之前,我们先来看一看 canvas 和 svg 是什么?
svg 是什么?
SVG 指可伸缩矢量图形 (Scalable Vector Graphics)。 SVG 用来定义用于网络的基于矢量的图形。 SVG 使用 XML 格式定义图形。 SVG 图像在放大或改变尺寸的情况下其图形质量不会有所损失。 SVG 是万维网联盟的标准。 SVG 与诸如 DOM 和 XSL 之类的 W3C 标准是一个整体。
canvas 是什么?
HTML5 的 canvas 元素使用 JavaScript 在网页上绘制图像。画布是一个矩形区域,您可以控制其每一像素。canvas 拥有多种绘制路径、矩形、圆形、字符以及添加图像的方法。
知道了 svg 和 canvas 是什么之后,我们就来比较一下 canvas 和 svg。
canvas 和 svg 的区别比较:
首先我们从时间上看 canvas 与 svg 的区别:
canvas 是 html5 提供的新元素 <canvas>,而 svg 存在的历史要比 canvas 久远,已经有十几年了。
svg 并不是 html5 专有的标签,最初 svg 是用 xml 技术(超文本扩展语言,可以自定义标签或属性)描述二维图形的语言。
其次我们从功能上看 canvas 与 svg 的区别:
SVG 是一种使用 XML 描述 2D 图形的语言。 SVG 基于 XML,这意味着 SVG DOM 中的每个元素都是可用的。您可以为某个元素附加 JavaScript 事件处理器。 在 SVG 中,每个被绘制的图形均被视为对象。如果 SVG 对象的属性发生变化,那么浏览器能够自动重现图形。
Canvas 通过 JavaScript 来绘制 2D 图形。 Canvas 是逐像素进行渲染的。 在 canvas 中,一旦图形被绘制完成,它就不会继续得到浏览器的关注。如果其位置发生变化,那么整个场景也需要重新绘制,包括任何或许已被图形覆盖的对象。
最后我们来看 canvas 与 svg 技术应用上的比较:
canvas 不依赖分辨率。 canvas 支持事件处理器。 canvas 最适合带有大型渲染区域的应用程序(比如谷歌地图)。 canvas 复杂度高会减慢渲染速度(任何过度使用 DOM 的应用都不快)。 canvas 不适合游戏应用。
svg 依赖分辨率。 svg 不支持事件处理器。 svg 弱的文本渲染能力。 svg 能够以 .png 或 .jpg 格式保存结果图像。 svg 最适合图像密集型的游戏,其中的许多对象会被频繁重绘。
本篇文章到这里就结束了,对于 canvas 和 svg 的更多知识内容可以参考 HTML5 开发手册。
以上就是 canvas 与 svg 的区别有什么?canvas 和 svg 的区别比较的详细内容,更多请关注 php 中文网其它相关文章!
今天关于在 chrome 中使用 javascript 设置 SVG 属性 和谷歌javascript设置 的介绍到此结束,谢谢您的阅读,有关5 SVG animation tools to make creating SVG much easier、 或 都不是在 iphone 中动画、@vue/cli 3.0 使用 svg-sprite-loader 加载本地 SVG 文件、canvas 与 svg 的区别有什么?canvas 和 svg 的区别比较 等更多相关知识的信息可以在本站进行查询。