当前位置:网站首页>如何封装 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,应该可简单啦,我这里就不写啦
边栏推荐
猜你喜欢

JS兼容问题总结

The Industrial Metaverse Brings Changes to Industry

2022 May 1 Mathematical Modeling Question C Explanation

EasyCVR calls the cloud recording API and returns an error and no recording file is generated. What is the reason?

(ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性

阿里云国际版使用ROS搭建WordPress教程

Matlab画图1

袋鼠云思枢:数驹DTengine,助力企业构建高效的流批一体数据湖计算平台

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

How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
随机推荐
#yyds干货盘点# 面试必刷TOP101:链表相加(二)
How does EasyCVR call the double-speed playback of device recording through the interface?
谷歌开源芯片 180 纳米制造工艺
Babbitt | Metaverse daily must-read: Weibo animation will recruit all kinds of virtual idols around the world and provide support for them...
DHCP&OSPF组合实验演示(Huawei路由交换设备配置)
八猴渲染器是什么?它能干什么?八猴软件的界面讲解
Thrift installation configuration
Thrift安装配置
数据库SqlServer迁移PostgreSql实践
Google AppSheet: 无需编程构建零代码应用
Understanding of margin collapse and coincidence
用Excel绘制统计图
【注册荣耀开发者】赢【荣耀70】手机
OpenInfra Days China 2022|SelectDB与你共享 Apache Doris 在互联网广告业务中的实践
Create Sentinel high-availability cluster current limiting middleware from -99
YOLOv7-Pose尝鲜,基于YOLOv7的关键点模型测评
方法的重写
袋鼠云思枢:数驹DTengine,助力企业构建高效的流批一体数据湖计算平台
谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
2022 May 1 Mathematical Modeling Question C Explanation