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

效果视频

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

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

代码部分

<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

微信小程序 悬浮按钮相关推荐

  1. 微信小程序悬浮按钮-点击传参

    1.js-组件 Component({data: {play: false,type:''},properties: {},methods: {changePlay(){let flag = !thi ...

  2. 微信小程序——添加按钮格式

    微信小程序--添加按钮 步骤一:在wxml文件中添加按钮代码(图后提供可复制代码) <button class = "button_cat">炸炸呼呼</butt ...

  3. uni-app 微信小程序分享按钮

    uni-app 微信小程序分享按钮 官方文档说明 在 manifest.json 的 App SDK 配置里,勾选微信消息及朋友圈,并填写相关 appkey,微信 appkey 在需要分享的页面填写: ...

  4. 微信小程序退出按钮退出方式

    微信小程序退出按钮退出方式 1,只能跳转到 tabBar配置的页面 wx.switchTab({url:''../xxx/xxx}) 2.返回上一级页面 (delta:返回的页面数,如果delta大于 ...

  5. 小程序全局悬浮窗_微信小程序悬浮窗弹出怎么实现?

    微信小程序悬浮窗弹出怎么实现?很多的微信小程序管理员会在微信小程序界面开发微信小程序悬浮窗弹出功能,接下来小编会为大家介绍微信小程序悬浮窗弹出关注实现的全部步骤哦. 微信小程序悬浮窗弹出怎么实现? 微 ...

  6. 微信小程序浮动按钮_操作按钮悬浮固定在微信小程序底部的实现代码

    本章节主要介绍了如何将操作按钮悬浮固定在微信小程序底部?操作起来也比较简单,还不会的朋友一起跟着小编学习一下吧,希望对你们有所帮助. 常见的有加入购物车按钮.结算按钮.收货列表添加地址按钮. 以收货地 ...

  7. 微信小程序退出按钮回退到登录页面

    记录一下最近微信小程序 电能服务 开发遇到的一些问题 1,退出按钮一开始设置的是wx.navigateTo({url:"../login/login"}) 从登录页面输入账号进到小 ...

  8. 微信小程序:修改按钮BUTTON尺寸

    1.微信小程序BUTTON常见属性: 2.BUTTON宽高等样式的有效调整方法: 微信小程序当中通过wxss来设置button的宽高值并不起效果,而size属性却只有两个合法值,当我们想要自定义大小时 ...

  9. 微信小程序button按钮无法更改尺寸解决

    在微信小程序新版本中, button按钮 无法支持在wxss文件中 直接自定义width 和 height  解决方法有两种: 1. 推荐使用: 在根目录中的app.json文件中, 删除其中的 &q ...

最新文章

  1. Java-001-面向对象
  2. springboot简易集成mybatisPlus+多数据源
  3. 【数据结构】排序相关题目及各种排序方法的总结
  4. 安卓手机的a/span的宽高失效
  5. POJ-1062-昂贵的聘礼 (最短路)
  6. objective-C 2.0
  7. 编译生成动态链接库pdfium.dll
  8. 如何测试服务器端口是否能够访问(使用telnet命令)
  9. vivo Z1的USB调试模式在哪里,打开vivo Z1USB调试模式的经验
  10. MATLAB实现Enigma 密码机
  11. 移动硬盘读取速度突然变慢?教你7个方法解决
  12. nginx反向代理实践:将某个指定的域名代理到指定的服务
  13. 关于LeakCanary检测华为手机内存泄漏问题
  14. 【OpenCV入门教程之十七】OpenCV重映射 SURF特征点检测合辑
  15. 每天吃2根香蕉,30天后你会发现自己有惊人的变化!
  16. Spring Boot应用的启动和停止(Spring Boot应用通过start命令启动)
  17. 本地ISO文件作为YUM源
  18. 界面设计原则(china ui)
  19. 计算机辅助药物设计的一般原理,朱瑞新着--_计算机辅助药物设计(Ⅰ)--基本方法原理概要与实践详解.pdf...
  20. PTA提交注意(JAVA语言)

热门文章

  1. php 大型系统开法流程图,有一个php项目源码,如何搞清楚执行过程?画出其流程图...
  2. java 线程执行结束_Java_如何等待子线程执行结束
  3. plc控制可调节阀流程图_PLC控制的水箱液位控制系统毕业论文
  4. leetcode718 最长重复子数组
  5. C语言-- 大端小端详解
  6. Redis:08---字符串对象
  7. Android Glide图片加载框架(四)回调与监听
  8. Android设计模式之——Builder模式
  9. 成为更优秀的开发人员:第二步-知道你的核心竞争力
  10. Windows系统使用minGW+msys 编译ffmpeg 0.5的全过程详述