Skip to content
On this page

组件库文档 tmui.design

吸附器 Adsorb

3.0.9+新增
随意拖动后会在屏幕两侧自动吸附。也可以关闭吸附功能,达到任意拖动。主要场景为:媒体播放悬浮按钮的吸附,营销的小弹层自动吸附又可拖动防止遮挡页面。


🌶️ 示例

查看模拟效果
示例模板
vue
<template>
	<tm-app>
		<tm-sheet :followDark="false">
			<tm-text :font-size="26" label="吸附器,自动吸附在屏幕两边边缘"></tm-text>
			
			
		</tm-sheet>
		<tm-adsorb :adsorb="false" :offset="[left/2,top/2]" :width="300" :height="150">
			<view class="flex flex-row flex-row-center-center" style="width:300rpx;height:150rpx;background:green;border-radius: 10rpx;">
				<tm-text color="white" label="随意拖动"></tm-text>
			</view>
		</tm-adsorb>
		<tm-adsorb :offset="[left,top]" :width="120" :height="120">
			<view class="flex flex-row flex-row-center-center" style="width:120rpx;height:120rpx;background:red;border-radius: 120rpx;">
				<tm-text color="white" label="拖动吸附"></tm-text>
			</view>
		</tm-adsorb>
	</tm-app>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { onShow, onLoad } from "@dcloudio/uni-app";
import tmApp from "@/tmui/components/tm-app/tm-app.vue"
import tmSheet from "@/tmui/components/tm-sheet/tm-sheet.vue"
import tmText from "@/tmui/components/tm-text/tm-text.vue"
import tmRadio from "@/tmui/components/tm-radio/tm-radio.vue"
import tmRadioGroup from "@/tmui/components/tm-radio-group/tm-radio-group.vue"
import tmDivider from "@/tmui/components/tm-divider/tm-divider.vue"
import tmAdsorb from "@/tmui/components/tm-adsorb/tm-adsorb.vue"
const sys = uni.getSystemInfoSync()
const left = ref(uni.$tm.u.torpx(sys.windowWidth) - 160)
const top = ref(uni.$tm.u.torpx(sys.windowHeight) -160)

</script>

🌶️ 兼容性

APP-VUEAPP-NVUE小程序WEB/H5VUE3/TS
✔️✔️✔️✔️✔️

🌱 参数

参数名类型默认值描述
adsorbBooleantrue是否开启屏幕两侧自动吸附
durationNumber600开启吸附后,自动吸附的动画持续时间
widthNumber100宽度
heightNumber100高度
offsetArray<number>[0,0]默认的位置
adsorbXNumber0吸附的偏移量,比如为10:当向左吸附时,减去偏移量,向右是加上偏移量

🌹 事件

事件名参数返回数据描述

🌽 slot插槽

默认default

🥗 ref方法

方法名参数返回值描述