[每天進步一點點~] uni-app 懸浮按鈕-點擊向上展開的縱向菜單

制作uni-app可拖動【懸浮按鈕】,點擊【加號圖標(biāo)】后向上展開按鈕菜單,如下圖

image.png

<movable-area>是uni-app自帶的,可以到uni-app官網(wǎng)查看文檔


image.png

image.png

代碼部分

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);
        }
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容