组件库文档 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-VUE | APP-NVUE | 小程序 | WEB/H5 | VUE3/TS |
---|---|---|---|---|
✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
🌱 参数
参数名 | 类型 | 默认值 | 描述 |
---|---|---|---|
adsorb | Boolean | true | 是否开启屏幕两侧自动吸附 |
duration | Number | 600 | 开启吸附后,自动吸附的动画持续时间 |
width | Number | 100 | 宽度 |
height | Number | 100 | 高度 |
offset | Array<number> | [0,0] | 默认的位置 |
adsorbX | Number | 0 | 吸附的偏移量,比如为10:当向左吸附时,减去偏移量,向右是加上偏移量 |
🌹 事件
事件名 | 参数 | 返回数据 | 描述 |
---|
🌽 slot插槽
默认default
🥗 ref方法
方法名 | 参数 | 返回值 | 描述 |
---|