制作uni-app可拖動【懸浮按鈕】,點擊【加號圖標(biāo)】后向上展開按鈕菜單饵溅,如下圖
<movable-area>是uni-app自帶的,可以到uni-app官網(wǎng)查看文檔
代碼部分
html代碼
<movable-area class="fixed-box">
<movable-view class="fixed-button" direction="all" :inertia="true" y="100px">
<view class="menuBox">
<u-icon class="mainMenu" name="plus-circle" size="90" @click="declick"></u-icon>
<view class="posi" :animation="animationData">
<button style="background-color: transparent; display: inline-block; margin-top: 10rpx;" hover-class="none" open-type="contact">
<u-icon name="kefu-ermai" size="50"></u-icon>
</button>
<button style="background-color: transparent; display: inline-block; margin-top: 10rpx;" hover-class="none">
<u-icon name="map" size="50"></u-icon>
</button>
<button style="background-color: transparent; display: inline-block; margin-top: 10rpx;" hover-class="none">
<u-icon name="phone" size="50"></u-icon>
</button>
</view>
</view>
</movable-view>
</movable-area>
上面使用的是uView插件的圖標(biāo)妇萄,也可以換成圖片uni-app自帶的<image>組件蜕企,內(nèi)容可以根據(jù)自己需要替換。
<movable-area class="fixed-box">
<movable-view class="fixed-button" direction="all" :inertia="true" y="100px">
<view class="menuBox">
<image class="mainMenu" src="http://cdn.heijinka.vip/business_add.png" @click="declick"></image>
<view class="posi" :animation="animationData">
<button style="background-color: transparent; display: inline-block; margin-top: 10rpx;" hover-class="none" open-type="contact">
<image style="width: 50rpx; height: 50rpx;" src="http://cdn.heijinka.vip/business_my_photo.png" mode=""></image>
</button>
<image src="http://cdn.heijinka.vip/business_thumb.png" mode=""></image>
<image src="http://cdn.heijinka.vip/shop_call_phone.png" mode=""></image>
</view>
</view>
</movable-view>
</movable-area>
js代碼
export default {
data(){
return {
animationData: {},
off:true,
}
},
onLoad() {
this.animation = uni.createAnimation()
},
onShow(){
var animation = uni.createAnimation({
duration:500,
trmingFunction:'ease'
})
this.animation = animation
},
methods:{
// 懸浮按鈕
declick(){
if(this.off){
//使用動畫
this.rotateAndScale()
}else{
this.norotateAndScale()
}
this.off = !this.off
},
//定義動畫內(nèi)容
rotateAndScale(){
this.animation.rotate(0).translateY(-167).step();
//導(dǎo)出動畫數(shù)據(jù)傳遞給data層
this.animationData = this.animation.export();
},
//當(dāng)!off的時候動畫回到原始位置
norotateAndScale(){
this.animation.rotate(0).translateY(0).step();
this.animationData = this.animation.export();
},
}
}
css代碼
button::after{
border:none;
}
.menuBox{
width: 90rpx;
height: 100%;
z-index: 1;
position: relative;
right: -6rpx;
bottom: 0rpx;
overflow: hidden;
border-radius: 45rpx;
// background-color: red;
}
.fixed-box {
pointer-events: none;
width: 100vw;
height: 100vh;
position: fixed;
left: 2px;
bottom: 0;
z-index: 100000;
}
.fixed-button {
pointer-events: auto;
width: 110rpx;
height: 360rpx;
right: 0;
left: auto;
top: 60vh;
display: flex;
justify-content: center;
align-items: center;
border-radius: 55rpx;
}
.mainMenu{
width: 90rpx;
height: 90rpx;
background: #fff;
position: absolute;
left: 2rpx;
bottom: -2rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 45rpx;
}
.posi{
width: 108rpx;
height:360rpx!important;
position: absolute;
left: -6rpx;
bottom: -316rpx;
z-index:-1;
display: flex;
align-items: center;
flex-direction: column;
background-color: #fff;
border-radius: 54rpx;
}
.posi>image{
width: 50rpx;
height: 50rpx;
margin-top: 30rpx;
}
/* 適配iphonex 有底部橫條的 */
@supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
.fixed-box {
bottom: constant(safe-area-inset-bottom);
bottom: env(safe-area-inset-bottom);
}
}