【发布时间】:2016-10-24 02:17:43
【问题描述】:
我是 ReactJs 的新手,正在研究 SVG,
下面的 ReactJS 代码 sn-p 创建了 9 个用不同颜色填充的图块。
import React from 'react';
class SvgRectDashboard extends React.Component {
render(){
var svgText = (<svg height="170px" width="364px" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(0,0)">
<rect x="0" y="0" width="118" height="55" fill="#FFCC99" stroke="rgb(0,0,0)" id="rect11"></rect>
<rect x="0" y="55" width="118" height="55" fill="#FFCC66" stroke="rgb(0,0,0)" id="rect12"></rect>
<rect x="0" y="110" width="118" height="55" fill="#FFCC33" stroke="rgb(0,0,0)" id="rect13"></rect>
<rect x="118" y="0" width="118" height="55" fill="#FFCC00" stroke="rgb(0,0,0)" id="rect21"></rect>
<rect x="118" y="55" width="118" height="55" fill="#FF9600" stroke="rgb(0,0,0)" id="rect22"></rect>
<rect x="118" y="110" width="118" height="55" fill="#FF9600" stroke="rgb(0,0,0)" id="rect23"></rect>
<rect x="236" y="0" width="118" height="55" fill="#FF9700" stroke="rgb(0,0,0)" id="rect31"></rect>
<rect x="236" y="55" width="118" height="55" fill="#FF9933" stroke="rgb(0,0,0)" id="rect32"></rect>
<rect x="236" y="110" width="118" height="55" fill="#FF6600" stroke="rgb(0,0,0)" id="rect33"></rect>
</g>
</svg>);
return (<div>{svgText}</div>);
}
}
module.exports = SvgRectDashboard;
表情符号位于 img/svg/1f3c8.svg
我的要求是需要在一些图块(矩形图块)中插入表情符号,如图所示。
我尝试了以下方法。但我做不到。
<rect x="0" y="0" width="118" height="55" fill="background:'url(img/svg/1f600.svg)" stroke="rgb(0,0,0)" id="rect11"></rect>
<rect x="0" y="55" width="118" height="55" style={background:'url(img/svg/1f600.svg)} stroke="rgb(0,0,0)" id="rect11"></rect>
你能帮帮我吗?谢谢。
【问题讨论】:
-
您必须用图案填充矩形元素并配置图案,以便它拥有您想要的图像。
标签: html user-interface svg reactjs react-jsx