91名师指路-头部
91名师指路

uniapp实现悬浮按钮可拖拽

由于某些原因,现在不支持支付宝支付,如需要购买源码请加博主微信进行购买,微信号:13248254750

一:uniapp实现悬浮按钮可拖拽

1.1)代码如下

<template>
<view>

<button class="float-button" hover-class="hover-btn-bg" :style="{right: right + 'px', bottom: bottom + 'px'}" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
<uni-icons type="mic" size="40px" color="#fff" />
</button>

</view>
</template>

<script>
export default {
data() {
return {
startX: 0,
startY: 0,
moveX: 0,
moveY: 0,
right: 20,
bottom: 100
};
},
onLoad() {

},
methods: {
touchStart(e) {
this.startX = e.touches[0].clientX
this.startY = e.touches[0].clientY
},
touchMove(e) {
this.moveX = e.touches[0].clientX - this.startX
this.moveY = e.touches[0].clientY - this.startY
this.right -= this.moveX
this.bottom -= this.moveY
this.startX = e.touches[0].clientX
this.startY = e.touches[0].clientY
},
touchEnd(e) {
// do something
}
}
};
</script>

<style lang="scss">
.float-button {
position: fixed;
right: 15px;
bottom: 110px;
width: 55px;
height: 55px;
border-radius: 50%;
background: #39b54a;
text-align: center;
display: flex;
align-items:center;
justify-content: center;
box-shadow: 4px 4px 15px rgba(0, 0, 0, 0.4);
z-index: 999;
}
.hover-btn-bg{
background-color: green;
color: #fff;
}
</style>


1.2)效果图如下






参考资料:

https://blog.csdn.net/qq_35230125/article/details/130937318




2023-07-16 15:47:42     阅读(409)

名师出品,必属精品    https://www.91mszl.com

联系博主    
用户登录遮罩层
x

账号登录

91名师指路-底部