ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

可任意拖动的客服按钮

2019-07-20 09:37:58  阅读:236  来源: 互联网

标签:function 拖动 res pageY 可任意 pageX 按钮 var screenWidth


html:

 <button style="bottom:{{ballBottom}}px;right:{{ballRight}}px;" bindtouchmove="ballMoveEvent">  
 </button>

JS:

Page({
	    data: {
	        ballBottom: 240,
	        ballRight: 120,
	        screenHeight: 0,
	        screenWidth: 0,  
	   },
	   onl oad: function (option) {
	         var that = this;
	        wx.getSystemInfo({
	            success: function (res) {
	                that.setData({
	                    screenHeight: res.windowHeight,
	                    screenWidth: res.windowWidth,
	                });
	            }
	        });
	    },
	    ballMoveEvent: function (e) {
		        // console.log('我被拖动了....')
		        var touchs = e.touches[0];
		        var pageX = touchs.pageX;
		        var pageY = touchs.pageY;
		        //防止坐标越界,view宽高的一般
		        if (pageX < 30) return;
		        if (pageX > this.data.screenWidth - 30) return;
		        if (this.data.screenHeight - pageY <= 30) return;
		        if (pageY <= 30) return;
		        //这里用right和bottom.所以需要将pageX pageY转换
		        var x = this.data.screenWidth - pageX - 30;
		        var y = this.data.screenHeight - pageY - 30;
		        // console.log('x: ' + x)
		        // console.log('y: ' + y)
		        this.setData({
			            ballBottom: y,
			            ballRight: x
		        });
	    }
})

标签:function,拖动,res,pageY,可任意,pageX,按钮,var,screenWidth
来源: https://blog.csdn.net/qq_43218075/article/details/96562352

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有