当前位置:网站首页>如何封装 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,应该可简单啦,我这里就不写啦
边栏推荐
- 机器学习——线性回归
- 12. SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值
- Interval greedy (interval merge)
- [Web Automation Test] Quick Start with Playwright, 5 minutes to get started
- 离散化求前缀和
- DOM Clobbering的原理及应用
- 【软件工程之美 - 专栏笔记】37 | 遇到线上故障,你和高手的差距在哪里?
- 网站设计师:Nicepage 4.15 Crack By Xacker
- The prefix and discretization
- 用Excel绘制统计图
猜你喜欢

关于ETL的两种架构(ETL架构和ELT架构)

Nintendo won't launch any new hardware until March 2023, report says

力扣学习---0804

LVS负载均衡群集之原理叙述

【STM32】入门(五):串口TTL、RS232、RS485

How does EasyCVR call the double-speed playback of device recording through the interface?

自己经常使用的三种调试:Pycharm、Vscode、pdb调试

路由技术

The Industrial Metaverse Brings Changes to Industry

DOM Clobbering的原理及应用
随机推荐
FE01_OneHot-Scala应用
解决错误:The package-lock.json file was created with an old version of npm
火灾报警联网FC18中CAN光端机常见问题解答和使用指导
机器学习——线性回归
基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)
2022年7月31日 暑假第三周总结
通配符SSL证书不支持多域名吗?
vantui 组件 van-field 路由切换时,字体样式混乱问题
Alibaba Cloud International Edition uses ROS to build WordPress tutorial
How to make JS code unbreakable
如何进行自动化测试?
leetcode/有效的回文串,含有不需要判断回文的字符
智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?
DHCP&OSPF combined experimental demonstration (Huawei routing and switching equipment configuration)
链表的经典入门LeetCode题目
leetcode 13. 罗马数字转整数
数仓相关,总结
FE01_OneHot-Scala Application
Global electronics demand slows: Samsung's Vietnam plant significantly reduces capacity
golang安装和基础配置