当前位置:网站首页>微信小程序启动页的实现
微信小程序启动页的实现
2022-08-11 05:29:00 【wendZzz】
加班偷着懒没做一堆九月份迭代的工作,实现了一下小程序的启动页。效果是这样的:
关注公众号查看效果
app.json
将启动页路径放在pages数组的第一项,tabBar中list正常放置。
start.wxml
先写一个容器显示背景图片,image标签上使用bindload方法,动态计算屏幕宽高,以适应不同手机端的尺寸,让背景图更佳显示。
因为是云开发,图片刻意使用了云存储中图片资源,具体操作可回顾之前发布的视频教程。
<view wx:for='{
{testList}}' wx:for-item="item" wx:key="item">
<image src="{
{item.fileID}}" bindload="autoImage" style="width:{
{imgWidth}};height:{
{ imgHeight }}" />
</view>
用户信息展示,整体用容器包起来,做成绝对定位。open-data 标签可以免权限直接拿到用户的昵称头像等信息,只需要指定相应的type即可。
<view class="userinfo">
<view class="userinfo-avatar">
<open-data type="userAvatarUrl"></open-data>
</view>
<view class="userinfo-name">
<text>{
{msg}}</text>
<open-data type="userNickName"></open-data>
</view>
<button hover-class="btn_red" class="btn" bindtap="goToIndex">进入店铺</button>
</view>
start.wxss
进入店铺按钮有一个悬停效果,使用hover-class定义一个目标效果的class。

start.js
autoImage 方法如下,欢迎白嫖。
autoImage(e) {
var that = this;
var originalWidth = e.detail.width;
var originalHeight = e.detail.height;
var imageWidth = 0;
var imageHeight = 0;
wx.getSystemInfo({
complete: (res) => {
var winWidth = res.windowWidth;
if (originalWidth > winWidth) {
var autoWidth = winWidth;
var autoHeight = (autoWidth * originalHeight) / originalWidth;
imageWidth = autoWidth + 'px';
imageHeight = autoHeight + 'px';
} else {
imageWidth = originalWidth + 'px';
imageHeight = originalHeight + 'px';
}
that.setData({
imgWidth: imageWidth,
imgHeight: imageHeight
});
}
})
}
进入店铺按钮上绑定的事件,直接调用微信api,tab页跳转。
goToIndex() {
wx.switchTab({
url: '/pages/index/index',
});
}
边栏推荐
- Vscode remote connection server terminal zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting
- PAT乙级刷题之路
- Day 85
- gerrit configure SSH Key and account, email information
- Byte (byte) and bit (bit)
- 开源机器学习数据库OpenMLDB贡献者计划全面启动
- Day 78
- vscode插件开发——懒人专用markdown插件开发
- Jetpack use exception problem collection
- He Kaiming's new work ViTDET: target detection field, subverting the concept of layered backbone
猜你喜欢

mk file introduction

开源之夏 2022 火热来袭 | 欢迎报名 OpenMLDB 社区项目~

Day 82

Vscode remote connection server terminal zsh+Oh-my-zsh + Powerlevel10 + Autosuggestions + Autojump + Syntax-highlighting

Building a data ecology for feature engineering - Embrace the open source ecology, OpenMLDB fully opens up the MLOps ecological tool chain

The third phase of the contributor task is wonderful

gerrit configure SSH Key and account, email information

gerrit 配置SSH Key和账号、邮箱信息

JVM调优整理

JNI入门
随机推荐
Promise 中状态改变和回调执行先后顺序 和promise多次回调
JS事件循环机制
Regular expression replacement for batch quick modification code
OpenMLDB v0.5.0 发布 | 性能、成本、灵活性再攀高峰
JS进阶网页特效(pink老师笔记)
使用c语言实现井字棋(有源码,可以直接运行)
USB URB
Matplotlib找不到字体,打印乱码
Day 67
127.0.0.1 connection refused
typescript学习日记,从基础到进阶(第二章)
js learning advanced (event senior pink teacher teaching notes)
贡献者任务第三期精彩来袭
Open Source Machine Learning Database OpenMLDB Contributor Program Fully Launched
C language implementation guess Numbers (with source code, can be directly run)
mongoose连接mongodb不错,显示encoding没有定义
Day 79
Tinker接入全流程---配置篇
JS案例练习(pink老师经典案例)
Day 75