反应JS-使用SVG线性渐变不起作用 [英] react js - use svg linear gradient not working

查看:86
本文介绍了反应JS-使用SVG线性渐变不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个圆圈和一个要填充的圆弧, 我放上渐变,然后通过样式填充在路径上称呼他.

i have a circle and a grradient to fill in it, i put in the gradient and call him in path by style fill.

import React,{PropTyoes} from 'react';
import {connect} from 'react-redux';  
import * as Actions from '../controllers/Actions';


export default class MyComp extends React.Component {
    constructor(props, context){
        super(props, context); 
    }
render(){ 
      return (
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" viewBox="0 0 983.4 983.4">
  <g>
   <linearGradient id="linear-gradient" gradientUnits="userSpaceOnUse" x1="1041.6901" y1="169.485" x2="1383.9301" y2="169.485" gradientTransform="matrix(1 0 0 -1 -761.14 398.97)">
          <stop offset="0.14" stop-color="#2f343b" stop-opacity="0"/>
          <stop offset="0.43" stop-color="#337082" stop-opacity="0.41"/>
          <stop offset="0.67" stop-color="#369fb9" stop-opacity="0.73"/>
          <stop offset="0.79" stop-color="#37b1cf" stop-opacity="0.85"/>
        </linearGradient>
        <path id="gradient" style={{fill:'url(#linear-gradient)'}} className="cls-200" d="M622.8,119.6C512.1,72,385.5,78.9,280.6,138.1l134.3,232.6c31.2-16.8,68.2-18.5,100.9-4.8    L622.8,119.6z">
</g>
</svg>

它不起作用,有什么建议吗?

it's not working, any suggestions?

推荐答案

在反应中,线性渐变的属性形式有些不同,应该是这样的:

in react the attributes form of linear gradient are a bit diffrent and supposed to be like this:

<linearGradient id="linear-gradient" gradientUnits="userSpaceOnUse" x1="1041.6901" y1="169.485" x2="1383.9301" y2="169.485" gradientTransform="matrix(1 0 0 -1 -761.14 398.97)">
      <stop offset="14%" stopColor="#2f343b" stopOpacity="0%"/>
      <stop offset="43%" stopColor="#337082" stopOpacity="41%"/>
      <stop offset="67%" stopColor="#369fb9" stopOpacity="73%"/>
      <stop offset="79%" stopColor="#37b1cf" stopOpacity="85%"/>        </linearGradient>

这意味着语法应来自stop-color => stopColor

its mean that the syntax should be from stop-color => stopColor

偏移量应为百分比

ReactJs + svg

ReactJs + svg

这篇关于反应JS-使用SVG线性渐变不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆