微信小程序浮标,可以拖动,自动靠边隐藏一半客服图标功能

ops/2024/10/19 3:55:55/

不多说,直接上代码。全屏拖动无抖动,中间停留自动靠边,拖动隐藏一半,可自己根据代码改动为自己想要的效果

js代码

import { tpStaticUrl,basictpStaticUrl } from "../../../envConfig";
let app = getApp();
Component({ properties: { },data: {windowWidth: 0, // 手机宽度windowHeight:0, // 手机高度touX: 0,  // 拖动后的X坐标touY: 0, // 拖动后的Y坐标x: 250,//定位X轴位置y: 250, //定位Y轴位置icon_xiaodangjia: tpStaticUrl+'/web/wxapp/bxsc/icon_xiaodangjia.png', // },pageLifetimes: {  // 初始化show: function() { var that = this;// console.log('222222222')wx.getSystemInfo({ success: function(res) { console.log(res)that.setData({windowWidth: res.windowWidth, // 手机宽度 windowHeight: res.windowHeight, // 手机高度x: res.windowWidth - 50,y: res.windowHeight /2 - 20})},fail: function(res) { },complete: function(res) {  },})},hide: function() { },resize: function() { },},methods: { serviceClick(){ // chelink + '/xiaoDj/index.html?wxtoken=' + rInfo.wxtoken + '&openId=' + uidapp.globalData.webviewSrc = basictpStaticUrl + '/web/xiaoDj/index.html?wxtoken=' + app.globalData.userInfo.xtoken + '&openId=' + app.globalData.userInfo.gwOpenId + '&unionId=' + app.globalData.userInfo.unionId;wx.navigateTo({  //  reLaunch关闭所有页面跳转  关闭当前页面--跳转 redirectTo    navigateTo不关闭页面跳转url: "/pages/page/webView/webView"})},bindchange(e){this.setData({ touX: e.detail.x,touY: e.detail.y})//  console.log(e.detail)},bindtouchend(e){let _this = this;// console.log('停止',_this.data.touY,e)// setTimeout(function(){if(_this.data.touX + 50 > _this.data.windowWidth && _this.data.touY+50 < _this.data.windowHeight){ // 移动右边超过了边距_this.setData({ x: _this.data.windowWidth - 25,y: e.changedTouches[0].pageY-20// y: Number(JSON.parse(JSON.stringify(_this.data.touY)))})}if(_this.data.touX + 50 < _this.data.windowWidth && _this.data.touY+50 < _this.data.windowHeight){  // 没有超过的时候,自动在右边_this.setData({ x: _this.data.windowWidth - 50,y: e.changedTouches[0].pageY-20// y: Number(JSON.parse(JSON.stringify(_this.data.touY)))})}if(_this.data.touY+50 > _this.data.windowHeight){ // 滑到底部的时候_this.setData({x: _this.data.windowWidth-50, y: _this.data.windowHeight- 100// y: Number(JSON.parse(JSON.stringify(_this.data.touY)))})}// },1000)} }});

wxml 代码

<movable-area><movable-view x='{{x}}' y='{{y}}' direction="all" style="pointer-events: auto;" bindchange="bindchange" bindtouchend="bindtouchend"><div bindtap="serviceClick" class="kefu"><image src="{{icon_xiaodangjia}}" class="kefuIcon"></image></div></movable-view>
</movable-area>

wxss 代码

movable-area{ width: 100%;height:100%;/*设置透明不影响后面的操作*/pointer-events: none;position:fixed;text-align: center;right:0px;top:0px;background: none;z-index: 9999;}.kefu, .kefuIcon { /* width: 45px;height: 45px; */border: none;padding: 0;background: none;}.kefu image {display: inline-block;width: 96rpx;height: 100rpx;}/* .kefu image { max-width: 100%;max-height: 100%;} */.kefu button::after { border: none;}

http://www.ppmy.cn/ops/4102.html

相关文章

FreeLearning PHP 译文集翻译完成

使用 PHP 和 jQuery 构建游戏化 Web 站点使用 PHP7 构建 REST Web 服务PHP 入门指南CouchDB 和 PHP Web 开发初学者指南Vue2 和 Laravel5 全栈开发函数式 PHPAngular6 和 Laravel5 Web 全栈开发实用指南FuelPHP 高效开发学习手册PHP 数据对象学习手册PHP7 高性能开发学习手册La…

文章解读与仿真程序复现思路——电力自动化设备EI\CSCD\北大核心《考虑碳市场风险的热电联产虚拟电厂低碳调度》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…

分布式系统——全站监控

文章目录 全站监控要点**监控范围与对象****监控指标与数据****监控工具与技术****监控策略与实践****全站监控的价值** 实例展示 全站监控要点 全站监控是针对分布式架构中所有组件和服务进行全方位、多层次、实时的性能监控、状态检测和故障告警的系统化方法。在分布式环境下…

Web安全知识

第二章 虚拟机运行架构&#xff1a; 1.寄居结构 2.原生架构 软件 注&#xff1a;Hyper-V是在Windows 2008操作系统上 附录 连接FTP服务器过程&#xff1a; 1.下载了软件&#xff1a; 2.连接到ftp://10.0.105.223/服务器&#xff08;访问老师课堂资源地址&#xff09; 关闭…

C#发票检验真伪示例、全电票查验接口、发票OCR识别

假发票的最直接危害体现在税收的流失&#xff0c;但发票查验对于现如今票据量大的企业而言成为了一大难题&#xff0c;传统手动输入发票信息的方式已无法满足当下企业的需求。人工智能时代&#xff0c;“以票控账&#xff0c;以票审计&#xff0c;以票查税"是推动企业数字…

【大数据】Apache Knox 概述

Apache Knox 概述 1.概述1.1 Kerberos 封装1.2 简化客户端证书的管理1.3 Apache Ranger 集成1.4 Hadoop URLs VS Knox URLs 2.自定义 Apache Knox2.1 Topology2.2 Provider2.3 Services2.4 Personalized services 3.Tips3.1 Setting up SSL3.2 常见问题3.2.1 Bulky answer3.2.2…

uniapp+vue3监听输入框内容watch

代码 <view class"searchBox"><view class"searchLeft"><wh-icon name"search" size"40"></wh-icon><input type"text" placeholder"请输入搜索内容" v-model"search" /&g…

Go语言常见错误 | 工程组织不合理 (工程结构和包的组织)

编写程序的过程中,组织代码的方式,不仅影响到代码的质量,也决定了团队的协作效率。在使用Golang进行项目开发时,工程组织不合理(包括工程结构和包的组织)是个常见的问题。下文将详述这个问题,并提供改善的方案。 工程结构不合理 Golang项目的工程结构对于代码的模块性…