当前位置: 首页 > 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;}

相关文章:

  • 【rabbitMQ】模拟work queue,实现单个队列绑定多个消费者
  • gittee使用教学
  • 基于Solr的全文检索系统的实现与应用
  • 华为OD机试 - 部门人力分配(Java JS Python C)
  • FFmpeg抽取视频h264数据重定向
  • JAVA网络编程——BIO、NIO、AIO深度解析
  • Go Fyne 入门
  • docker-compose安装教程
  • 51单片机LED与无源蜂鸣器模块
  • Python高级算法——动态规划
  • 【期末计算机组成原理速成】第三章:存储器
  • 【MYSQL】单表查询
  • 《算法与数据结构》答疑
  • ACM32F403/F433 12 位多通道,支持 MPU 存储保护功能,应用于工业控制,智能家居等产品中
  • uniapp下拉刷新
  • 【划重点】MySQL技术内幕:InnoDB存储引擎
  • 2017届校招提前批面试回顾
  • Debian下无root权限使用Python访问Oracle
  • download使用浅析
  • dva中组件的懒加载
  • ECMAScript 6 学习之路 ( 四 ) String 字符串扩展
  • Java,console输出实时的转向GUI textbox
  • JavaScript/HTML5图表开发工具JavaScript Charts v3.19.6发布【附下载】
  • leetcode386. Lexicographical Numbers
  • Logstash 参考指南(目录)
  • 从0搭建SpringBoot的HelloWorld -- Java版本
  • 官方解决所有 npm 全局安装权限问题
  • 排序算法学习笔记
  • 适配mpvue平台的的微信小程序日历组件mpvue-calendar
  • 赢得Docker挑战最佳实践
  • MPAndroidChart 教程:Y轴 YAxis
  • ​Base64转换成图片,android studio build乱码,找不到okio.ByteString接腾讯人脸识别
  • ​LeetCode解法汇总1276. 不浪费原料的汉堡制作方案
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • # Swust 12th acm 邀请赛# [ E ] 01 String [题解]
  • #vue3 实现前端下载excel文件模板功能
  • #我与Java虚拟机的故事#连载08:书读百遍其义自见
  • (C++)八皇后问题
  • (第二周)效能测试
  • (附源码)springboot 房产中介系统 毕业设计 312341
  • (附源码)springboot电竞专题网站 毕业设计 641314
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (附源码)ssm航空客运订票系统 毕业设计 141612
  • (附源码)SSM环卫人员管理平台 计算机毕设36412
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (七)c52学习之旅-中断
  • (七)理解angular中的module和injector,即依赖注入
  • (三)Kafka离线安装 - ZooKeeper开机自启
  • (生成器)yield与(迭代器)generator
  • (实测可用)(3)Git的使用——RT Thread Stdio添加的软件包,github与gitee冲突造成无法上传文件到gitee
  • (转)ABI是什么
  • (转)c++ std::pair 与 std::make
  • .CSS-hover 的解释
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • @selector(..)警告提示