• uniapp 悬浮球


    悬浮球组件

    在这里插入图片描述

    <template>
    	<view
    		class="hover_ball_cell"
    		:style="{ width: `${diameter}px`, height: `${diameter}px`, top: `${top}px`, left: `${left}px` }"
    		@touchmove.prevent="touchmove"
    		@touchend="touchend"
    		@touchcancel="touchcancel"
    		@tap="onTap"
    		:animation="ballAnimation"
    	>
    		<view v-if="iconUrl == ''" class="wave" />
    		<image v-else :src="iconUrl"  mode="">image>
    	view>
    template>
    
    <script>
    export default {
    	props: {
    		iconUrl: {
    			type: String,
    			default: ''
    		},
    		 onClickHover: {
    		      type: Function,
    		      require: true,
    		      default: null,
    		    },
    	},
    	data() {
    		return {
    			diameter: 0,
    			top: 0,
    			left: 0,
    			isMove: false,
    			ballAnimation: {},
    			timeout: null,
    			modile: {},
    		};
    	},
    	name: 'hover-ball',
    	created() {
    		let _this = this;
    		_this.modile = uni.getSystemInfoSync();
    		_this.top = _this.modile.safeArea.height - 180;
    		_this.left = _this.modile.safeArea.width;
    		_this.diameter = _this.modile.screenHeight / 15;
    		let create = uni.createAnimation({
    			duration: 400,
    			timingFunction: 'ease-in'
    		});
    		create.translate('-100%').step();
    		setTimeout(() => {
    			// _this.left = _this.modile.safeArea.width
    			create.translate('-50%').step();
    			_this.ballAnimation = create.export();
    		}, 0)
    	},
    	methods: {
    		onTap() {
    			let _this = this;
    			let x = '0';
    			if (2 * _this.left >= _this.modile.safeArea.width) {
    				x = '-100%';
    			}
    			let create = uni.createAnimation({
    				duration: 0
    			});
    			create.translate(x).step();
    			_this.ballAnimation = create.export();
    			_this.overBall();
    			_this.onClickHover()
    		},
    		touchmove(e) {
    			let _this = this;
    			_this.isMove = true;
    			if (_this.timeout != null) {
    				clearTimeout(_this.timeout);
    				_this.timeout = null;
    			}
    			var touch = e.touches[0] || e.changedTouches[0];
    			_this.left = touch.clientX;
    			_this.top = touch.clientY;
    		},
    		touchend(e) {
    			let _this = this;
    			if (!_this.isMove) {
    				return;
    			}
    			_this.finish(e);
    		},
    		touchcancel(e) {
    			let _this = this;
    			if (!_this.isMove) {
    				return;
    			}
    			_this.finish(e);
    		},
    		finish(e) {
    			let _this = this;
    			_this.isMove = false;
    			var touch = e.touches[0] || e.changedTouches[0];
    			_this.left = touch.clientX;
    			_this.top = touch.clientY;
    			let x = '0';
    			if (2 * _this.left + _this.diameter >= _this.modile.safeArea.width) {
    				_this.left = _this.modile.safeArea.width;
    				x = '-100%';
    			} else {
    				_this.left = _this.modile.safeArea.left;
    			}
    			if (_this.top > _this.modile.safeArea.height + _this.modile.safeAreaInsets.bottom) {
    				_this.top = _this.modile.safeArea.height + _this.modile.safeAreaInsets.bottom; 
    			} else if (_this.top < - _this.diameter / 2) {
    				_this.top = - _this.diameter / 2;
    			}
    			let create = uni.createAnimation({
    				duration: 0
    			});
    			console.log(x)
    			create.translate(x).step();
    			_this.ballAnimation = create.export();
    			_this.overBall();
    		},
    		overBall() {
    			let _this = this;
    			_this.timeout = setTimeout(() => {
    				_this.timeout = null;
    				let create = uni.createAnimation({
    					duration: 400,
    					timingFunction: 'ease-in'
    				});
    				create.translate('-50%').step();
    				_this.ballAnimation = create.export();
    			}, 1200);
    		}
    	}
    };
    script>
    
    <style lang="less" scoped>
    .hover_ball_cell {
    	position: fixed;
    	overflow: hidden;
    	border-radius: 50%;
    	border: 4rpx solid #67c23a;
    	background: #ffffff;
    	transform: translate(-50%, 0);
    	padding: 4rpx;
    	display: flex;
    	justify-content: center;
    	align-items: center;
    	z-index: 100000;
    
    	.wave {
    		position: relative;
    		width: 100%;
    		height: 100%;
    		background-image: linear-gradient(-180deg, #aaff80 13%, #67c23a 91%);
    		border-radius: 50%;
    	}
    	
    	image{
    		width: 60%;
    		height: 60%;
    	}
    }
    style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168

    使用组件

    在这里插入图片描述

    <template>
    	<view class="version">
    		<hover-ball :onClickHover="onClickHover" :iconUrl="iconUrl"/>
    	view>
    template>
    
    <script>
    export default {
    	data() {
    		return {
    			iconUrl: '../../static/image/shopping-cart.png'
    		};
    	},
    	onLoad(option) {
    	},
    	onShow() {
    	},
    	methods: {
    		onClickHover(){
    			uni.$u.route('/pages/secondary/shopping-cart');
    		},
    	}
    };
    script>
    
    <style scoped lang="scss">
    
    style>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    快速入门SpringMVC,详解原理
    美团一面面经及详细答案
    产品经理就业喜报:有努力,回报就在眼前
    手把手教学mfc140u.dll丢失的解决方法,快速解决mfc140u.dll丢失
    B_QuRT_User_Guide(34)
    Python:入门与基本语法
    【计网 CDN】计算机网络 CDN(Content Delivery Network)分布式网络架构详解:中科大郑烇老师笔记 (八)
    java+jsp基于ssm矿场仓储管理系统-计算机毕业设计
    下载文件时的文件名中文乱码问题,文件名丢失
    数据分析与取证capture.pcapng
  • 原文地址:https://blog.csdn.net/qq_43869822/article/details/126619740