当前位置: 首页 > news >正文

uniapp移动端悬浮按钮(吸附边缘)

Uniapp移动端悬浮按钮可以通过CSS实现吸附边缘的效果。具体实现步骤如下:

html:

<movable-area class="movable-area"><movable-view class="movable-view" :position="position" :x="x" :y="y" :direction="direction":damping="damping" @change="onChange" @touchend="onTouchend" @click="record"><image :src="url+'/uploads/20231209/45a4381a8d120d73e310d10ad5aadc41.png'" mode="widthFix"class="iconImage"></image></movable-view></movable-area>

js:

export default {data() {return {x: 364, //x坐标y: 700, //y坐标x1: 0,x2: 0,y1: 0,y2: 0,move: {x: 0,y: 0}}},onLoad() {},props: {damping: {type: Number,default: 10},direction: {type: String,default: "all"},position: {type: Number,default: 4},},mounted() {uni.getSystemInfo({success: (res) => {this.x1 = 0;this.x2 = parseInt(res.windowWidth) - 50;this.y1 = 0;this.y2 = parseInt(res.windowHeight) - 20;setTimeout(() => {if (this.position == 1 || this.position == 2) this.y = parseInt(this.y2 * 0.2);if (this.position == 3 || this.position == 4) this.y = parseInt(this.y2 * 0.8);if (this.position == 1 || this.position == 3) this.x = parseInt(this.x1);if (this.position == 2 || this.position == 4) this.x = parseInt(this.x2);this.move.x = this.x;this.move.y = this.y;}, 1000)}})},methods: {onChange(e) {if (e.detail.source == "touch") {this.move.x = e.detail.x;this.move.y = e.detail.y;}},onTouchend() {this.x = this.move.x;this.y = this.move.y;setTimeout(() => {if (this.move.x < this.x2 / 2) this.x = this.x1;else this.x = this.x2;console.log(this.x, this.y)}, 100)}}

css:

.iconImage {display: block;width: 120rpx;height: 120rpx;animation: iconImage 5s linear infinite;}@keyframes iconImage {0% {-webkit-transform: rotate(0deg);}25% {-webkit-transform: rotate(90deg);}50% {-webkit-transform: rotate(180deg);}75% {-webkit-transform: rotate(270deg);}100% {-webkit-transform: rotate(360deg);}}.contact {width: 50px;height: 50px;overflow: hidden;position: absolute;left: 0px;top: 0px;border-radius: 100%;opacity: 0;}.movable-area {height: 100vh;width: 750rpx;top: 0;position: fixed;pointer-events: none;z-index: 9999999;}.movable-view {width: 96rpx;height: 96rpx;background-color: #2561EF;border-radius: 50%;pointer-events: auto;position: relative;z-index: 9999999;display: flex;align-items: center;justify-content: center;}.movable-view image {width: 50rpx;height: 50rpx;}

http://www.lryc.cn/news/257520.html

相关文章:

  • 【成功】Linux安装Mysql8并设置远程连接
  • 高效纯化树脂A-2313 CPR
  • uni-app实现安卓原生态调用身份证阅读器读卡库读身份证和社保卡、银行卡、IC卡等功能
  • 【QT】QComboBox和QPlainTextEdit基本介绍和应用示例
  • Path的使用-path绘制折线的时候带上圆角
  • Go Fyne 入门
  • 如何为游戏角色3D模型设置纹理贴图
  • 2024 年 SEO 现状
  • Mac虚拟机CrossOver23破解版下载和许可证下载
  • 宝藏级实用工具,制作电子书轻而易举
  • 虚拟局域网(VLAN)解析(Virtual Local Area Network)(用于在不受物理位置限制的情况下将设备划分到同一网络或不同网络)
  • uni-app 微信小程序之好看的ui登录页面(四)
  • 解决火狐浏览器拖拽事件打开新页面的问题
  • 以为回调函数是同步的(js的问题)
  • 如何在小米路由器4A千兆版刷入OpenWRT并通过内网穿透工具实现公网远程访问
  • diffusers pipeline拆解:理解pipelines、models和schedulers
  • Spring 装配Bean详解
  • udp多播组播
  • 逆向修改Unity的安卓包资源并重新打包
  • pycharm中py文件设置参数
  • 简单实现Spring容器(二) 封装BeanDefinition对象放入Map
  • 信创运维产业的发展与趋势:IT管理的新视角
  • 算法通关村第十七关 | 黄金挑战 | 跳跃游戏
  • 思科最新版Cisco Packet Tracer 8.2.1安装
  • 【LeetCode热题100】【滑动窗口】找到字符串中所有字母异位词
  • logback的使用
  • IntelliJ IDEA无公网远程连接Windows本地Mysql数据库提高开发效率
  • VS Code使用教程
  • StarRocks数据模型之主键模型(当前版本v3.1)
  • 正确使用React组件缓存