当前位置:网站首页>如何封装 svg
如何封装 svg
2022-08-04 18:17:00 【Anita-Sun】
svg
- svg 代表可缩放矢量图形,以 XML 格式定义基于矢量的图形
- 例:
<html> <body> <h1>My first SVG</h1> <svg width="100" height="100"> <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" /> </svg> </body> </html>
在 react 中封装 svg
背景
- 我将 svg 图片导入了项目文件夹中,例
<svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg"> <rect x="0.0758667" width="32.1457" height="32" fill="black"/> <g clip-path="url(#clip0_55_1126)"> <path d="M23.1806 9H9.11684V23H23.1806V9Z" fill="white" fill-opacity="0.01"/> <path d="M10.8748 11.625L15.0939 16.5302V20.213L17.2035 21.25V16.5302L21.4226 11.625H10.8748Z" stroke="#EBEBEB" stroke-width="0.875" stroke-linejoin="round"/> </g> <defs> <clipPath id="clip0_55_1126"> <rect width="14.0637" height="14" fill="white" transform="translate(9.11684 9)"/> </clipPath> </defs> </svg> - 如果直接使用的话,无法控制 svg 图片的大小,所以我想是否可以封装一下
过程
- 将 svg 图片分为两部分,外边 svg 标签部分和内容部分
<svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg"> </svg><rect x="0.0758667" width="32.1457" height="32" fill="black"/> <g clip-path="url(#clip0_55_1126)"> <path d="M23.1806 9H9.11684V23H23.1806V9Z" fill="white" fill-opacity="0.01"/> <path d="M10.8748 11.625L15.0939 16.5302V20.213L17.2035 21.25V16.5302L21.4226 11.625H10.8748Z" stroke="#EBEBEB" stroke-width="0.875" stroke-linejoin="round"/> </g> <defs> <clipPath id="clip0_55_1126"> <rect width="14.0637" height="14" fill="white" transform="translate(9.11684 9)"/> </clipPath> </defs> - 创建
downArrow.tsx文件夹import React from "react"; export const DownArrow = () => { return ( <> <rect x="0.816376" width="32.1457" height="32" fill="black"/> <g clipPath="url(#clip0_39_400)"> <path d="M23.9211 9H9.85735V23H23.9211V9Z" fill="white" fillOpacity="0.01"/> <path d="M20.6981 14.25L17.1822 17.75L13.6663 14.25" stroke="#EBEBEB" strokeWidth="0.875" strokeLinecap="round" strokeLinejoin="round"/> </g> <defs> <clipPath id="clip0_39_400"> <rect width="14.0637" height="14" fill="white" transform="translate(9.85735 9)"/> </clipPath> </defs> </> ); } - 封装 svg.jsx,应该可简单啦,我这里就不写啦
边栏推荐
- 报道称任天堂在2023年3月前不会推出任何新硬件产品
- 离散化求前缀和
- clickhouse 上下线表
- OpenInfra Days China 2022 | SelectDB to share with you the Apache Doris in Internet advertising business practices
- leetcode/含有所有字符的最短字符串
- 敏捷开发项目管理的一些心得
- (ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性
- A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?
- LVS+Keepalived群集
- 离线同步odps到mysql 中文乱码是因为?mysql已是utf8mb4
猜你喜欢

Matlab画图1

Flink/Scala - Storing data with RedisSink

npm配置国内镜像(淘宝镜像)

Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?

How to make JS code unbreakable

Introduction of three temperature measurement methods for PT100 platinum thermal resistance

YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评

unity中实现ue眼球的渲染

方法的重写

用Excel绘制统计图
随机推荐
防火墙基础之防火墙做出口设备安全防护
图解LeetCode——899. 有序队列(难度:困难)
工业元宇宙对工业带来的改变
Alibaba Cloud International Edition uses ROS to build WordPress tutorial
The prefix and discretization
路由懒加载
golang安装和基础配置
ATF中断处理的设计模型
EasyCVR本地接入国标设备映射公网后,本地设备出现无法播放与级联的解决方法
darknet source code reading notes-02-list.h and lish.c
Thrift installation configuration
数据集成:holo数据同步至redis。redis必须是集群模式?
智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?
谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?
C#爬虫之通过Selenium获取浏览器请求响应结果
【杰神说说】物联大师2.0版本预告
Investigation and Research Based on the Involution Behavior of College Students
部署LVS-DR群集
2022 May 1 Mathematical Modeling Question C Explanation