微信小程序 悬浮按钮

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

效果视频

https://pan.baidu.com/s/1yfrDaG9YAX0--v0EA3awZA

布局需要按照圆形排列,所以我们需要计算每个点的坐标

f7635b1673ae611b0766bda74e75caa6e3c.jpg

代码部分

<view style='position:fixed;' wx:for="{{list}}" wx:for-index="index"><image animation="{{index==0 ? animationData0:(index==1?animationData1:(index==2?animationData2:(index==3?animationData3:animationData4)))}}" class='img-before' style="margin-top:{{item.top}}px;margin-left:{{item.left}}px;" src='https://res.o2o.cn/img/0b145cb287ee4e4292d724cdd39c1d75.png'></image><image class='img' bindtap='showOther' style="margin-top:100px;margin-left:300px;z-index:99999;" src='https://res.o2o.cn/img/0b145cb287ee4e4292d724cdd39c1d75.png'></image></view>

首先fixed,绝对定位是少不掉的

css

.img{width:80rpx;height:80rpx;position:absolute;
}
.img-before{width:80rpx;height:80rpx;position:absolute;opacity:0;
}

最后是js

let that;
const app = getApp();
Page({/*** 页面的初始数据*/data: {showButton: false,animationData0: {},animationData1: {},animationData2: {},animationData3: {},animationData4: {},list: [{}, {}, {}, {}, {}],radius: 80},/*** 生命周期函数--监听页面加载*/onLoad: function(options) {},showOther: function(e) {var that = this;if (that.data.list.length > 5) {return} else {var list = that.data.listfor (let i = 0; i <list.length; i++) {if (i == 0) {list[0]["left"] = e.currentTarget.offsetLeft;list[0]["top"] = e.currentTarget.offsetTop - that.data.radius * Math.sin(2 * Math.PI / 360 *90);list[0]["animationData"] =that.data.animationData0;}if (i == 1) {list[1]["left"] = e.currentTarget.offsetLeft - that.data.radius * Math.cos(2 * Math.PI / 360 * 45);list[1]["top"] = e.currentTarget.offsetTop - that.data.radius * Math.sin(2 * Math.PI / 360 *45);list[1]["animationData"] = that.data.animationData1;}if(i==2){list[2]["left"] = e.currentTarget.offsetLeft - that.data.radius * Math.cos(2 * Math.PI / 360 * 0);list[2]["top"] = e.currentTarget.offsetTop - that.data.radius * Math.sin(2 * Math.PI / 360 * 0);list[2]["animationData"] = that.data.animationData2;}if (i == 3){list[3]["left"] = e.currentTarget.offsetLeft - that.data.radius * Math.cos(2 * Math.PI / 360 * -45);list[3]["top"] = e.currentTarget.offsetTop - that.data.radius * Math.sin(2 * Math.PI / 360 * -45);list[3]["animationData"] = that.data.animationData3;}if (i == 4){list[4]["left"] = e.currentTarget.offsetLeft;list[4]["top"] = e.currentTarget.offsetTop - that.data.radius * Math.sin(2 * Math.PI / 360 * -90);list[4]["animationData"] = that.data.animationData4;}}that.setData({list: list})if (that.data.showButton) {var animation0 = wx.createAnimation({duration: 2500,timingFunction: 'ease',})that.animation0 = animation0;animation0.opacity(0).step();var animation1 = wx.createAnimation({duration: 2000,timingFunction: 'ease',})that.animation1 = animation1;animation1.opacity(0).step();var animation2 = wx.createAnimation({duration: 1500,timingFunction: 'ease',})that.animation2 = animation2;animation2.opacity(0).step();var animation3 = wx.createAnimation({duration: 1000,timingFunction: 'ease',})that.animation3 = animation3;animation3.opacity(0).step();var animation4 = wx.createAnimation({duration: 500,timingFunction: 'ease',})that.animation4 = animation4;animation4.opacity(0).step();that.setData({animationData0: animation0.export(),animationData1: animation1.export(),animationData2: animation2.export(),animationData3: animation3.export(),animationData4: animation4.export(),showButton: false,})} else {var animation0 = wx.createAnimation({duration: 500,timingFunction: 'ease',})that.animation0 = animation0;animation0.opacity(1).step();var animation1 = wx.createAnimation({duration: 1000,timingFunction: 'ease',})that.animation1 = animation1;animation1.opacity(1).step();var animation2 = wx.createAnimation({duration: 1500,timingFunction: 'ease',})that.animation2 = animation2;animation2.opacity(1).step();var animation3 = wx.createAnimation({duration: 2000,timingFunction: 'ease',})that.animation3 = animation3;animation3.opacity(1).step();var animation4 = wx.createAnimation({duration: 2500,timingFunction: 'ease',})that.animation4 = animation4;animation4.opacity(1).step();that.setData({animationData0: animation0.export(),animationData1: animation1.export(),animationData2: animation2.export(),animationData3: animation3.export(),animationData4: animation4.export(),showButton: true,})}}}
})

其中,位置需要用Math.sin()/Math.cos()函数去计算,还用到了微信动画的api

ps:代码比较粗糙,只是为了做这个效果,具体优化地方根据自己的使用情况修改。

转载于:https://my.oschina.net/maxdeath/blog/2248829

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/450421.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C语言const关键字—也许该被替换为readolny

const 是constant 的缩写&#xff0c;是恒定不变的意思&#xff0c;也翻译为常量、常数等。很不幸&#xff0c;正是因为这一点&#xff0c;很多人都认为被const 修饰的值是常量。这是不精确的&#xff0c;精确的说应该是只读的变量&#xff0c;其值在编译时不能被使用&#xff…

dbus服务自启动方法

Linux 一般发行版上 "/usr/share/dbus-1/services/"目录就是dbus放service文件的地方。 需要自动启动的服务器 就在这个目录放一个 service文件&#xff0c;内容如下&#xff1a; $ cat /usr/share/dbus-1/services/dhcdbd.service [D-BUS Service] Namecom.redhat.…

在Spring Boot中使用 @ConfigurationProperties 注解

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 上一篇博客写了 如何在Spring Boot application中配置mail . 使用 Value 注解注入属性. 但 Spring Boot 提供了另一种方式 &#xff0c;能…

Micronaut教程:如何使用基于JVM的框架构建微服务

\本文要点\\Micronaut是一种基于jvm的现代化全栈框架&#xff0c;用于构建模块化且易于测试的微服务应用程序。\\tMicronaut提供完全的编译时、反射无关的依赖注入和AOP。\\t该框架的开发团队和Grails框架的开发团队是同一个。\\tMicronaut框架集成了云技术&#xff0c;服务发现…

C语言extern关键词—最会带帽子的关键字

extern&#xff0c;外面的、外来的意思。那它有什么作用呢&#xff1f;举个例子&#xff1a;假设你在大街上看到一个黑皮肤绿眼睛红头发的美女&#xff08;外星人&#xff1f;&#xff09;或者帅哥。你的第一反应就是这人不是国产的。extern 就相当于他们的这些区别于中国人的特…

解决Coldfusion连接MySQL数据库的问题

在连接MySQL时&#xff0c;出现了如下错误&#xff1a; Connections to MySQL Community Server are not supported. Please contact MySQL to obtain a MySQL Enterprise or Commercial version. 解决方案&#xff1a; step 1: download the JDBC driver JDBC Driver for MySQ…

范式知识点

Mysql数据库 ⽬前关系数据库有六种范式&#xff1a; 第⼀范式&#xff08;1NF&#xff09;、第⼆范式&#xff08;2NF&#xff09;、第三范式&#xff08;3NF&#xff09;、巴斯-科德范式 &#xff08;BCNF&#xff09;、第四范式(4NF&#xff09;和第五范式&#xff08;5NF&a…

Tensorflow入门----占位符、常量和Session

安装好TensorFlow之后&#xff0c;开一个python环境&#xff0c;就可以开始运行和使用TensorFlow了。 先给一个实例&#xff0c; #先导入TensorFlowimport tensorflow as tf # Create TensorFlow object called hello_constanthello_constant tf.constant(Hello World!) with …

C语言union关键字

union 关键字的用法与struct 的用法非常类似。union 维护足够的空间来置放多个数据成员中的“一种”&#xff0c;而不是为每一个数据成员配置空间&#xff0c;在union 中所有的数据成员共用一个空间&#xff0c;同一时间只能储存其中一个数据成员&#xff0c;所有的数据成员具有…

js 深拷贝 和 浅拷贝

1、 ...运算符 &#xff08;浅拷贝&#xff09; let obj {a:1,b:2}; let obj2 {...obj}; obj.a3 obj //{a: 3, b: 2} obj2 //{a: 1, b: 2}a {a:[{b:1}]}; b a ;b.a[0].b 2; //b {a:[{b:2}]}a // a {a:[{b:2}]} 2、 JSON.parse(JSON.stringify(参数))…

软考如何备考

软考上半年 报名时间 3月 考试时间 5月 备考持续时间&#xff1a;一个半月&#xff0c;每天至少两个小时。 第一轮 基础知识轮&#xff0c; 15天 在这一轮中如果碰到无法理解的知识点一定不要过于纠结&#xff0c;往后学&#xff0c;一般后面的学着学着之前的内容就…

Python学习第一天-第2节

*本节课内容参见&#xff1a;https://www.cnblogs.com/jin-xin/articles/7459977.html运行第一个Python程序 print(hello world) 将文本文件保存为以.py结尾的文件&#xff0c;如hello_world.py &#xff0c;在终端中&#xff0c;运行命令&#xff1a;Python hello_world.py&am…

SpringMVC之组合注解@GetMapping

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 Spring4.3中引进了&#xff5b;GetMapping、PostMapping、PutMapping、DeleteMapping、PatchMapping&#xff5d;&#xff0c;来帮助简化…

资源下载地址

1、nginx http://nginx.org/en/download.html 2、nodejs http://nodejs.cn/download/ 3、vscode https://code.visualstudio.com/ 4、canal https://github.com/alibaba/canal/releases/download/canal-1.1.4/canal.deployer-1.1.4.tar.gz 5、jenkins https://jenkins.io/i…

C语言volatile关键字—最易变的关键字

volatile 是易变的、不稳定的意思。很多人根本就没见过这个关键字&#xff0c;不知道它的存在。也有很多程序员知道它的存在&#xff0c;但从来没用过它。我对它有种“杨家有女初长成,养在深闺人未识” 的感觉。volatile 关键字和const 一样是一种类型修饰符&#xff0c;用它修…

mysql 备份脚本

#!/bin/bash INNOBACKUPEXFULL"/usr/bin/innobackupex" MYSQL_CMD --socket/ssd/mysql/3346/tmp/mysql.sock --userroot --passwordmysqlpassword --port3346 MYSQL_UP --userroot --passwordmysqlpassword --port3346 #mysqladmin的用户名和密码 TMPLOG"/dat…

爆栈的处理方法

爆栈指递归中&#xff0c;存储的信息量大于系统栈的内存。 信息量包括元素编号&#xff0c;每一层中开的变量。 和递归的层数正相关。 &#xff08;虽然noip一般开栈&#xff09; 1.手写栈 while(top){ int xsta[top]; for(each son) if(has son){ //blablabla sta[top]son; h…

项目面试题

项目面试题 1.描述最熟悉的或者&#xff08;最近&#xff09;的一个项目 &#xff1f; 目的&#xff1a;检测技术和项目的熟悉程度工作职责 回答&#xff1a;项目名称&#xff0c;项目的甲方&#xff0c;背景&#xff0c;实现的目的和意义&#xff0c;该项目主要是为了解决什…

MySQL定时备份(全量备份+增量备份)

MySQL 定时备份 参考 zone7_ 的 实战-MySQL定时备份系列文章 参考 zmcyu 的 mysql数据库的完整备份、差异备份、增量备份 更多binlog的学习参考马丁传奇的 MySQL的binlog日志&#xff0c;这篇文章写得认真详细&#xff0c;如果看的认真的话&#xff0c;肯定能学的很好的。 如果…

java 接口可以多继承

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 接口是常量值和方法定义的集合。接口是一种特殊的抽象类。 java类是单继承的。classB Extends classA java接口可以多继承。Interface…