- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 svg 元素,我想缩放它并让它从下到上缩放。
这是一个代码笔示例:https://codepen.io/knightjdr/pen/QQeNOj
我使用 animateTransform 实现了缩放,并通过移动原点让它从下到上缩放。这在 Chrome 和 Firefox 中工作正常,但在从左上角开始缩放的 Safari 中却不行。
根据 Mozilla ( https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin ),Safari 中对 svg 的 transform-origin 的支持是未知的,但我的示例似乎不支持它。
如果有人有建议,我正在寻找一种在 Safari 中解决此问题的方法,或者寻找实现这种缩放效果的替代方法。
这里是codepen的缩写代码:
.steam {
-webkit-transform-origin: 93px 130px;
}
<svg>
<g class="steam">
<path
fill="#763626"
d="..."
/>
<path
fill="#AC867C"
d="..."
/>
<animateTransform
additive="sum"
attributeName="transform"
begin="0"
dur="2"
from="0 0"
repeatCount="indefinite"
to="1 1"
type="scale"
/>
</g>
</svg>
最佳答案
transform-origin 属性在所有浏览器中都有很好的支持,那么为什么不在 SVG 之外制作动画呢?此外,通过将 viewBox 和 preserveAspectRatio 添加到您的 SVG 元素,您可以控制 viewBox 的大小并确保变换直接从元素的中心发生。
在 Safari 上测试,它完美运行。
下面的演示:
svg {
max-height: 100vh;
transform-origin: center bottom;
animation: steam-animation 1s infinite;
}
@keyframes steam-animation {
0% { transform: scale(0,0); opacity: 0;}
100% { transform: scale(1,1); opacity: 1;}
}
<svg viewBox="0 0 175 150" preserveAspectRation="xMinYMin">
<g class="steam">
<path
fill="#763626"
d="M138.422,14.336c-8.441,0-16.208,2.682-22.398,7.174C112.494,9.193,98.66,0,82.121,0C71.58,0,62.141,3.738,55.762,9.634c-4.618-1.997-9.784-3.118-15.239-3.118c-19.607,0-35.502,14.441-35.502,32.255c0,7.312,2.682,14.053,7.195,19.463C4.667,61.181,0,65.241,0,69.725c0,8.997,18.785,16.291,41.957,16.291c13.149,0,24.88-2.35,32.573-6.025c5.51,5.703,13.458,9.283,22.294,9.283c9.634,0,18.205-4.261,23.719-10.884c5.288,2.777,11.383,4.368,17.879,4.368c20.201,
0,36.578-15.316,36.578-34.21S158.624,14.336,138.422,14.336z"
/>
<path
fill="#AC867C"
d="M160.967,55.897c0-14.556-10.783-26.355-24.085-26.355c-6.238,0-11.923,2.595-16.201,6.853c-5.278-4.719-13.404-7.747-22.525-7.747c-4.029,0-7.862,
0.592-11.344,1.657c-4.261-1.628-9.067-2.55-14.158-2.55c-17.475,0-31.642,10.8-31.642,24.122c0,3.975,1.269,7.722,3.503,11.028c-12.563,2.494-21.449,8.614-21.449,15.774c0,9.375,15.224,16.975,34.003,16.975c7.695,0,14.79-1.277,20.488-3.429c5.172,5.813,14.364,9.683,24.849,9.683c13.623,0,25.072-6.53,28.342-15.373c0.756,0.116,1.542,0.185,2.355,0.185c4.958,0,9.055-2.296,9.789-5.294C153.286,78.504,160.967,68.182,160.967,55.897z"
/>
<line
fill="none"
stroke="#763626"
stroke-width="4"
stroke-miterlimit="10"
x1="91.474"
y1="74.599"
x2="91.474"
y2="125"
/>
<line
fill="none"
stroke="#763626"
stroke-width="4"
stroke-miterlimit="10"
x1="61.647"
y1="83.668"
x2="82.528"
y2="125"
/>
<line
fill="none"
stroke="#763626"
stroke-width="4"
stroke-miterlimit="10"
x1="121.3"
y1="83.668"
x2="100.419"
y2="125"
/>
</g>
</svg>
关于html - Safari 中具有缩放和变换原点的 SVG animateTransform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49139339/
有什么办法可以制作 animateTransform 的变换 值(value)转化为相对值(value)?像 20%,30% 以外的 px 值。 例如, 在这段代码中,有没有办法定义来自 和 至 相
我想同时对缩放和旋转对象进行动画处理。到目前为止,我的尝试失败了。我只能链接动画(旋转,然后缩放)但不能一起旋转和缩放。 我错过了什么? 我试图删除“additive =“sum”,但这只是覆盖并忽略
我有一条路径要使用 animateTransform 设置动画.我想同时翻译和缩放路径。它不起作用。显然只有第二个动画在工作:在这种情况下 scale .我究竟做错了什么? svg{ width:30
在以下示例中,我需要同时执行所有动画。但只适用于最后一个。 getValue('project_icon'); ?>" /> Action 已被js触发: v
我正在尝试让#moon svg 组遵循一条路径并应用定时转换。在这种情况下,我似乎无法让 animateTransform 工作。 当我设置 animateMotion 时,它会导致 移出框架。我用属
我正在尝试向简单的 SVG SMIL 动画添加计时功能。显然可以使用 keySplines 设置时间/缓动属性,但是在我的示例中它不起作用:
当第一个元素悬停时,其他元素也会激活。但是当第二个元素悬停时,其他元素将不起作用。如何让每一个item的动画都一个一个的触发? body { display: flex; justify-co
在来自 https://upload.wikimedia.org/wikipedia/commons/9/97/Moire_Lines.svg 的文件中 动画在 Chrome、Iron、Opera、V
我试图在我的 SVG 中让两个动画相继运行。 这就是它们的写入方式。它们被写入一个组,里面有一些原语。我正在尝试让整个组旋转然后平移。 但是当我运行这个时,变换似乎在第一个动画结束时重置
我一直在尝试通过 Javascript 将 SVG 动画元素附加到组中。 “animateTransform”似乎仅在我使用数值时才起作用;当我使用通过 getBBox 定义的变量时它不会播放(请参阅
我想让我的 svg 动画在单击 html 按钮时运行。我想我可以通过在 animateTransform 中设置 begin="click 来实现这一点,然后在 animateTransform (或
我正在尝试沿其轴旋转我的 SVG 图像,我可以使用以下代码成功地做到这一点: 我的问题是是否有一种方法可以将动画的重新启动处理为一两秒。将 repeatCount 设置为无限期,它会立即重新启动它。
我有一个 SVG 图形,我正在通过 animateTransform 制作动画。它动画化,然后停留在屏幕上,直到您单击它,然后它缩小到 0 并且无法恢复。我想要做的是在最后一个动画结束(缩放为 0)后
我有一个 svg 元素,我想缩放它并让它从下到上缩放。 这是一个代码笔示例:https://codepen.io/knightjdr/pen/QQeNOj 我使用 animateTransform 实
如果您查看此 SVG,我正在为 transform 属性设置动画,默认情况下它从左上角移动。如何将其更改为从中心设置动画? 我已经尝试过的: This answer说
尝试使用 JavaScript 移动 SVG 元素进行交互式游戏; 但是,动画结束后该
我想通过变换矩阵(即时决定)变换 SVG Canvas 上的元素。我可以使用 JQuery-SVG animate() 来完成,但结果一点也不流畅。所以我想使用原生的 SVG animateTrans
我正在尝试对 SVG 文件中的某些路径进行动画处理,但我似乎无法附加必要的 标记为这些路径的子路径。 这是我的代码: currentState.addEventListener("click", fu
SVG animateTransform 与 css3 转换不同。 svg.truck { overflow: visible; } .smoke{ transform-origin: 50%
我使用 animateTransform 创建了一个自定义 PreLoader 屏幕 和 keyframes 在我的 svg 图像上。 当我处理图像时,它们在所有浏览器上都运行良好。但是一旦我在我的
我是一名优秀的程序员,十分优秀!