微信小程序 懸浮按鈕

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.pswp.cn/news/450421.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/450421.shtml
英文地址,請注明出處:http://en.pswp.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…