当前位置:网站首页>如何封装 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,应该可简单啦,我这里就不写啦
边栏推荐
- Codeforces积分系统介绍
- Web端即时通讯技术:WebSocket、socket.io、SSE
- 谷歌开源芯片 180 纳米制造工艺
- 如何给MySQL添加自定义语法 ?
- The prefix and discretization
- Thrift installation configuration
- 【无标题】
- Hezhou Cat1 4G module Air724UG is configured with RNDIS network card or PPP dial-up, and the development board is connected to the Internet through the RNDIS network card (taking the RV1126/1109 devel
- 工业元宇宙对工业带来的改变
- Nintendo won't launch any new hardware until March 2023, report says
猜你喜欢
JS兼容问题总结
"No title"
Matlab画图1
巴比特 | 元宇宙每日必读:微博动漫将招募全球各类虚拟偶像并为其提供扶持...
谷歌开源芯片 180 纳米制造工艺
Thrift IDL示例文件
YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
基于 eBPF 的 Kubernetes 可观测实践
Hezhou Cat1 4G module Air724UG is configured with RNDIS network card or PPP dial-up, and the development board is connected to the Internet through the RNDIS network card (taking the RV1126/1109 devel
什么是网站监控,网站监控软件有什么用?
随机推荐
阿里云国际版使用ROS搭建WordPress教程
2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers
路由懒加载
袋鼠云思枢:数驹DTengine,助力企业构建高效的流批一体数据湖计算平台
leetcode/有效的回文串,含有不需要判断回文的字符
【STM32】STM32单片机总目录
Investigation and Research Based on the Involution Behavior of College Students
2022年7月31日 暑假第三周总结
Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
LVS+Keepalived群集
Short-term reliability and economic evaluation of resilient microgrids under incentive-based demand response programs (Matlab code implementation)
linux下Mysql的简单操作
leetcode/含有所有字符的最短字符串
语音识别学习资源
Go 言 Go 语,一文看懂 Go 语言文件操作
DHCP&OSPF combined experimental demonstration (Huawei routing and switching equipment configuration)
July 31, 2022 Summary of the third week of summer vacation
火灾报警联网FC18中CAN光端机常见问题解答和使用指导
静态iP与权限更改[通俗易懂]
基于 eBPF 的 Kubernetes 可观测实践