准备工作到此已经完成,接下来铅誉进入项目配置使用;
可以使用view text等标签引入iconfont;
页面效果:
其中:
引入VantUI组件内容可参考 VantUI官网快速上手 进行配置;
页面效果:
小程序实现换肤功能结构<view class='page' id='{{SkinStyle}}'><view class='header'>
<view class='h-skin iconfont {{SkinStyle!=="normal"?"icon-moon":"icon-sun"}}' bindtap='bgBtn'></view>
</view></view>
要模拟一个可修改的根节点page 根据 id='{{SkinStyle}}’ 来配置theme.wxss 每个页面@import 这个theme.wxss#dark .header{}切换按钮全局变量:globalData:{skin:“normal”}. //渣嫌app.js文件中页面中bgBtn事件bgbtn:function(){ this.setData({
SkinStyle: app.globalData.skin //设置SkinStyle的值
}) wx.setStorage({ //设置storage key: 'skins', data: app.globalData.skin,
})}页面的Page中的onLoad事件里,读取手友storage并设置SkinStyle的值毕梁槐onLoad: function (options) { var that=this
wx.getStorage({
key: 'skins',
success: function(res) {that.setData({ SkinStyle: res.data }) }, })}
如何引入外部字体库iconfont的图标,具体滑差如下
直接使用阿里巴巴的网络路径
选择iconfont图标
官网:阿里巴巴矢量字体库
步骤:阿里巴巴字体库使用方法
全局盯让谨引入app.wxss
?
12345678910111213141516171819202122232425262728293031323334@font-face { font-family: 'iconfont'/* project id 518032 */ src: url('//at.alicdn.com/t/font_518032_t2q88z3jok8iwwmi.eot') src: url('//at.alicdn.com/t/font_518032_t2q88z3jok8iwwmi.eot?#iefix') format('embedded-opentype'), url('//at.alicdn.com/t/font_518032_t2q88z3jok8iwwmi.woff') format('woff'), url('//at.alicdn.com/t/font_518032_t2q88z3jok8iwwmi.ttf') format('truetype'), url('//at.alicdn.com/t/font_518032_t2q88z3jok8iwwmi.svg#iconfont') format('svg')}.iconfont { font-family:"iconfont" !important font-size:60rpx font-style:normal -webkit-font-smoothing: antialiased -moz-osx-font-smoothing: grayscale}/*本项目使用的18个图标 */.icon-zhiding:before{content: '\e739'}.icon-zuojiantou:before{content: '\e736'}.icon-youjiantou:before{content: '\e735'}.icon-shangjiantou:before{content: '\e734'}.icon-xiajiantou1:before{content: '\e733'}.icon-xiajiantou:before{content: '\e6cc'}.icon-gengduotianchong:before{content: '\e67f'}.icon-erweima:before{content: '\e65f'}.icon-fenleiorguangchangorqita:before{content: '\e64f'}.icon-dibiao:before{content: '\e64d'}.icon-bangzhu:before{content: '\e64a'}.icon-xinfeng:before{content: '\e640'}.icon-duihuaxinxi:before{content: '\e639'}.icon-sousuo:before{content: '\e62f'}.icon-shouye:before{content: '\e62d'}.icon-shezhi:before{content: '\e62a'}.icon-shanchu:before{content: '\e629'}.icon-dianhua:before{content: '\e61b'}使用图标
?
123456789101112131415161718192021222324<view> <icon class="iconfont icon-zhiding"></icon> <icon class="iconfont icon-zuojiantou"></icon> <icon class="iconfont icon-youjiantou"></icon> <icon class="iconfont icon-shangjiantou"></icon> <icon class="iconfont icon-xiajiantou1"></icon> <icon class="iconfont icon-xiajiantou"></icon></view><view> <icon class="iconfont icon-gengduotianchong"><凯基/icon> <icon class="iconfont icon-erweima"></icon> <icon class="iconfont icon-fenleiorguangchangorqita"></icon> <icon class="iconfont icon-dibiao"></icon> <icon class="iconfont icon-bangzhu"></icon> <icon class="iconfont icon-xinfeng"></icon></view><view> <icon class="iconfont icon-duihuaxinxi"></icon> <icon class="iconfont icon-sousuo"></icon> <icon class="iconfont icon-shouye"></icon> <icon class="iconfont icon-shezhi"></icon> <icon class="iconfont icon-shanchu"></icon> <icon class="iconfont icon-dianhua"></icon></view>效果图
注意:此处实现采用的是无APPID的开发模式,实际应用应该在微信小程序管理平台的开发设置中配置合法域名。
下载到本地
步骤
字体文件转化成base64格式
解压压缩包 —- 找到ttf格式文件 —- 上传到平台转化为base64格式 —- 下载压缩包 —- 将css文件名改为wxss —- 放入项目文件夹 —- 用@import全局引入 —- 使用
使用—-引入及全局定义
?
123456789101112131415161718192021222324@import "src/css/icon.wxss".iconfont { font-family: "iconfont" font-size:60rpx}/*本项目使用的18个图标 */.icon-zhiding:before{content: '\e739'}.icon-zuojiantou:before{content: '\e736'}.icon-youjiantou:before{content: '\e735'}.icon-shangjiantou:before{content: '\e734'}.icon-xiajiantou1:before{content: '\e733'}.icon-xiajiantou:before{content: '\e6cc'}.icon-gengduotianchong:before{content: '\e67f'}.icon-erweima:before{content: '\e65f'}.icon-fenleiorguangchangorqita:before{content: '\e64f'}.icon-dibiao:before{content: '\e64d'}.icon-bangzhu:before{content: '\e64a'}.icon-xinfeng:before{content: '\e640'}.icon-duihuaxinxi:before{content: '\e639'}.icon-sousuo:before{content: '\e62f'}.icon-shouye:before{content: '\e62d'}.icon-shezhi:before{content: '\e62a'}.icon-shanchu:before{content: '\e629'}.icon-dianhua:before{content: '\e61b'}开发使用
?
123456789101112131415161718192021222324<view> <icon class="iconfont icon-zhiding"></icon> <icon class="iconfont icon-zuojiantou"></icon> <icon class="iconfont icon-youjiantou"></icon> <icon class="iconfont icon-shangjiantou"></icon> <icon class="iconfont icon-xiajiantou1"></icon> <icon class="iconfont icon-xiajiantou"></icon></view><view> <icon class="iconfont icon-gengduotianchong"></icon> <icon class="iconfont icon-erweima"></icon> <icon class="iconfont icon-fenleiorguangchangorqita"></icon> <icon class="iconfont icon-dibiao"></icon> <icon class="iconfont icon-bangzhu"></icon> <icon class="iconfont icon-xinfeng"></icon></view><view> <icon class="iconfont icon-duihuaxinxi"></icon> <icon class="iconfont icon-sousuo"></icon> <icon class="iconfont icon-shouye"></icon> <icon class="iconfont icon-shezhi"></icon> <icon class="iconfont icon-shanchu"></icon> <icon class="iconfont icon-dianhua"></icon></view>效果图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)