博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SVG:linearGradient渐变在直线上失效的问题解决方案
阅读量:4316 次
发布时间:2019-06-06

本文共 892 字,大约阅读时间需要 2 分钟。

SVG开发里有个较为少见的问题。

对x1=x2或者y1=y2的直线(line以及path),比如:

 

如果,stroke里使用的是渐变效果,那么,在各种浏览器上都会出现同一个BUG,这条线消失了。

原因不好排查,但是道理很简单,参考:

Keyword objectBoundingBox should not be used when the geometry of the applicable element has no width or no height, such as the case of a horizontal or vertical line, even when the line has actual thickness when viewed due to having a non-zero stroke width since stroke width is ignored for bounding box calculations. When the geometry of the applicable element has no width or height and objectBoundingBox is specified, then the given effect (e.g., a gradient or a filter) will be ignored.

简而言之,就是说:

关键字objectBoundingBox这玩意儿,在元素没有宽度或者高度的时候,会失去作用。

 

linearGradient渐变又依赖这个属性,所以失效了。

解决方案很简单,为linearGradient加上属性gradientUnits="userSpaceOnUse"

gradientUnits是用于规定元素的坐标系统的,有两个属性userSpaceOnUse和objectBoundingBox,后者是默认的。

具体的说明参考:

 

转载于:https://www.cnblogs.com/anrainie/p/5996496.html

你可能感兴趣的文章
MySQL常见注意事项及优化
查看>>
流畅的Python (Fluent Python) —— 前言
查看>>
Jquery-menu-aim流畅的菜单滑动体验
查看>>
Jquery EasyUI修改行背景的两种方式
查看>>
嵌入式Linux学习笔记(0)基础命令。——Arvin
查看>>
二分图匹配
查看>>
c++ 模板template
查看>>
CString的成员函数详解
查看>>
Appium Studio 初体验(windows做ios自动化,录制appium脚本)
查看>>
Linux常用命令
查看>>
整体二分&cdq分治 ZOJ 2112 Dynamic Rankings
查看>>
【POJ2976】Dropping tests (01分数规划入门题)
查看>>
通过正则表达式获取url中参数
查看>>
cxx signal信号捕获
查看>>
《Android开发艺术探索》读书笔记——Cha3.2.3改变布局参数实现View的滑动
查看>>
python闭包与装饰器
查看>>
Acegi 源码解释
查看>>
Activity的几种启动跳转方式
查看>>
LCA最近公共祖先Tarjan(离线)
查看>>
牛客练习赛16 E求值
查看>>