【发布时间】:2017-11-22 12:28:30
【问题描述】:
我最近几天才开始使用 SVG,并为番茄应用程序构建了一个简单的径向动画。我发现动画的起点与我在桌面浏览器(0 度)上设置和看到的不同。下面我在 Safari 中的 iPhone 6 屏幕截图显示了我所看到的(在 Chrome 和 Firefox 中也有相同的结果)。您可以亲自观看此直播here。
圆的初始起始路径为 90 度,因此我应用以下方法来获得所需的起始点:
<circle className={className} transform="rotate(-90, 50, 60)">
我花了一上午的时间搜索帖子,我真正发现的唯一与我所看到的内容相关的是这个答案底部的评论here。我去看了规范并阅读了它,但我真的不明白我是否更好地使用path 或评论中的这个半圆想法(我不明白)全部)。我现在的理解是,在移动浏览器中,<circle /> 被解释为初始起点与桌面浏览器中的不同(也许我错了,这是与操作系统相关的问题?)。
谁能解释一下如何解决这个问题?我不希望有人解决我的问题,只是朝着正确的方向轻推。在过去的 2 个小时里,我一直在阅读帖子和谷歌搜索,但没有运气,也没有对整个问题有更多的了解。提前感谢您的帮助。
<circle /> 的完整代码:
import PropTypes from 'prop-types'
import { styles } from '../../lib'
/**
* @function Circle
* @description renders <circle /> that is conditionally animated.
*
* @prop {String} className
* @prop {Number} duration - desired length of timer formatted to seconds
* @returns React Element
*/
const Circle = ({ className, duration }) => (
<circle className={className} transform="rotate(-90, 50, 60)">
<style jsx>{`
circle {
cx: 50;
cy: 60;
fill: transparent;
r: 35;
stroke-width: 4;
}
.outer {
stroke: ${styles.colors.highLight};
}
.overlay {
stroke: none;
stroke-dasharray: 219; /* NOTE: https://stackoverflow.com/a/33922201/6520579 */
stroke-linecap: round;
}
.cooldownAnimation {
animation: ${duration}s linear normal forwards cooldown;
stroke: ${styles.colors.text};
}
.timerAnimation {
-webkit-animation: ${duration}s linear normal forwards timer;
animation: ${duration}s linear normal forwards timer;
stroke: ${styles.colors.text};
}
@-webkit-keyframes timer {
from {
stroke-dashoffset: 219;
}
to {
stroke-dashoffset: 0;
}
}
@keyframes timer {
from {
stroke-dashoffset: 219;
}
to {
stroke-dashoffset: 0;
}
}
@-webkit-keyframes cooldown {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 219;
}
}
@keyframes cooldown {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 219;
}
}
@media (orientation: landscape) {
circle {
r: 50;
}
.overlay {
stroke-dasharray: 314;
}
@-webkit-keyframes timer {
from {
stroke-dashoffset: 314;
}
to {
stroke-dashoffset: 0;
}
}
@keyframes timer {
from {
stroke-dashoffset: 314;
}
to {
stroke-dashoffset: 0;
}
}
@-webkit-keyframes cooldown {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 314;
}
}
@keyframes cooldown {
from {
stroke-dashoffset: 0;
}
to {
stroke-dashoffset: 314;
}
}
}
`}</style>
</circle>
)
Circle.propTypes = {
className: PropTypes.string,
duration: PropTypes.number
}
export default Circle
【问题讨论】:
标签: javascript ios css animation svg