像很多APP,下载完毕开始使用的时候都会有一个至少三个页面启动页面,我就想小程序是不是也可以实现这种效果,但是通过搜索我好像并没有找到类似的解决办法。
我后来看到轮播图,突发灵感想到一个办法:
利用swiper组件做成三个全屏页面轮播,最后一个页面设置一个“点击进入”的button进行小程序授权登录。
这样既解决了启动页面要求只出现一次的问题,还不用再另外设置授权登录。
粘贴代码如下
wxml部分:
<view>
<swiper indicator-dots="true" autoplay="true" interval="5000" class='hahahh'>
<swiper-item>
<image src="/images/static/welcome1.jpg"></image>
</swiper-item>
<swiper-item>
<image src="/images/static/welcome2.jpg" ></image>
</swiper-item>
<swiper-item>
<image src="/images/static/welcome.jpg" class='welcome-img'></image>
<button class='welcome-btn' bindtap='login'>点击开启</button>
</swiper-item>
</swiper>
</view>
wxss部分:
.hahahh {
height: 1398rpx;
}
image {
height: 1398rpx;
width: 100%;
}
.welcome-img {
position: absolute;
z-index: 1;
}
.welcome-btn {
background-color: #73b69b;
color: white;
font-size: 38rpx;
width: 330rpx;
height: 90rpx;
text-align: center;
line-height: 90rpx;
border-radius: 10px;
position: absolute;
bottom: 80rpx;
left: 20px;
right:20px;
z-index: 2;
}
js部分:
Page({
wx.switchTab({
url: "../photo/photo"
});
wx.login({
success(res) {
if (res.code) {
// 发起网络请求
wx.request({
url: 'https://test.com/onLogin',
data: {
code: res.code
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
}
})
最后就成为这个样子啦(缩放之后截屏的,效果可能不太好看哈)