Comments (3)
你的意思是不输入size而是通过样式 就能处理icon的尺寸?size应是必须的,因为模板里size传给svg了,不是用来生成样式。
实际需求,图标宽度、高度需要在外层样式控制的较多
这个是怎么理解?能否截个图之类的说明一下?
from mini-program-iconfont-cli.
我先说改造的过程吧(微信小程序为例):
一、 把生成的图标代码样式里边的高和宽去掉
//也就是 libs/grenerateWechatComponent.js 里边
width: {{svgSize}}px; height: {{svgSize}}px;
//去掉后,生成的代码,图标的代码view的style里不会有width, height。
二、在样式模板里,添加可外层控制的样式,最终改造为:
.icon {
background-repeat: no-repeat;
width: var(--iconfont-width, #size#px);
height: var(--iconfont-height, #size#px);
background-size: 100% auto;//这里看需要吧, 我的项目图标使用的都是正方式的多,如果有特殊的宽高比例,可能需要调整。
}
三、 为了能够编译样式模板里的#size#,需要自动替换变量值后,再生成样式文件。
var wxssFile = getTemplate_1.getTemplate('wechat.wxss');
wxssFile = replace_1.replaceSize(wxssFile, config.default_icon_size);
fs_1.default.writeFileSync(path_1.default.join(saveDir, fileName + '.wxss'), wxssFile);
--------- 以上改造完成, 可以 npx iconfont-wechat 了。
四、 应用(小程序为例):
定义默认图标大小:
page{
--iconfont-width: 36rpx;
--iconfont-height: 36rpx;
}
也可以在特别的地方用样式定义图标的宽高:
//LESS
.middle-text-with-icon{
display: flex;
flex-flow: row;
font-size: 28rpx;
.icon, .text{
display: flex;
flex-flow: column;
justify-content: center;
}
.icon{
margin-right: 15rpx;
//重定义图标大小
--iconfont-width: 28rpx;
--iconfont-height: 28rpx;
}
}
WXML代码:
<view class="middle-text-with-icon">
<view class="icon">
<iconfont name="iconName"></iconfont>
</view>
<view class="text">与图标大小一致的文字</view>
</view>
----------- 结束!!!
from mini-program-iconfont-cli.
对了,svg里边的width和height不用去掉,对应:
var template = "<svg viewBox='" + data.$.viewBox + "' xmlns='http://www.w3.org/2000/svg' width='{{svgSize}}px' height='{{svgSize}}px'>";
上方代码中的width,和height无需去掉。
from mini-program-iconfont-cli.
Related Issues (20)
- 请问mpvue该怎么使用呢? HOT 3
- 微信推出的kbone框架支持吗?
- 666666 HOT 1
- 可以支持h5吗? HOT 1
- 请问我已经生成了链接然后按照步骤做 并没有icon 但是用你的链接可以 HOT 1
- 是否还在维护,能支持渐变色就完美了
- 支持color传入var变量
- 小程序"use_rpx": true后还是使用px单位
- 如何在小程序自定义组件中使用呢?在页面中可以但在组件中就不行了
- 测试快手小程序
- 非常好用!👍不过微信小程序IDE组件有CSS报错
- template加上`eslint-disable`
- 生成的组件里是否可以提供图标名称的列表
- 按照操作了,没有任何效果,iconfont大小为0,不知道什么原因。在微信小程序上面没有效果
- ERR! code E404 HOT 2
- 请问如果压缩一下
- iconfont 网站没有链接生成了,如何引入本地js?
- 【强烈建议】在微信小程序的json模板中添加一行,让外部可以应用图标的样式
- 请问能否支持生成相应页面的iconfont,各个页面使用自己的iconfont,方便管理。 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini-program-iconfont-cli.