uniapp movable-area组件使用

看过很多文章,基本都是把官方文档搬过来并没有实际用法

<movable-area class="movable-area">
		<movable-view class="movable-view" direction="vertical" :y="nextMovableY" @change="onChange" out-of-bounds="true" @touchend="touchEnd" animation="true">
            //  滑动的内容
        <movable-view>
<movable-area>


// css

.movable-area {
		position: fixed;
		top: 0%;
		left: 0;
		width: 100%;
		height: 100vh;
		pointer-events: none;

		.movable-view {
			width: 100%;
			pointer-events: all;
			position: relative;
		}
	}

去获取屏幕高度和滑动的距离

onLoad(){
		try {
            // 这个封装的获取屏幕高度方法
			this.screenHeight = getApp().globalData.systemInfo.screenHeight
			this.swiperHeight = this.screenHeight / 4
			this.mapHeight = this.screenHeight - this.screenHeight / 3
            // 滑块最初位置
			this.nextMovableY = this.mapHeight - 50
		} catch (e) {}
}

// 组件的 onChange 事件
onChange(e) {
	this.movableY = e.detail.y
},
touchEnd(e) {
        // 这里就是计算滑动的距离
		this.nextMovableY = this.movableY
		setTimeout(() => {
			if(this.movableY > this.screenHeight / 2 - 100) {
				this.nextMovableY = this.mapHeight - 50
				
			} else if(this.nextMovableY > this.swiperHeight && this.nextMovableY < this.mapHeight) {
				this.nextMovableY = this.swiperHeight - 50
			
				} 
			}, 100)
},

 可直接粘贴使用,修改一下滑块的距离即可

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值