Yt-UI
首页
快速开始
组件文档
首页
快速开始
组件文档
  • 表单组件

    • 输入框 Input
    • 多行输入框 Textarea
    • 开关 Switch
    • 多选框组 CheckboxGroup
    • 单选框组 RadioGroup
    • 滑块 Slider
    • 选择器 Picker
    • 日历 Calendar
    • 表单 Form
  • 展示组件

    • 头像 Avatar
    • 徽标 Badge
    • 卡片 Card
    • 标签 Tag
    • 步骤条 Steps
    • 结果页 Result
    • 空状态 Empty
    • 虚拟列表 VirtualList
  • 交互组件

    • 按钮 Button
    • 悬浮按钮 FAB
    • 图标 Icon
    • 搜索 Search
    • 分段器 Segment
    • 轮播 Swiper
    • 指示点 Dots
  • 反馈组件

    • 加载 Loading
    • 弹窗 Popup
    • 遮罩层 Overlay
    • 通告栏 NoticeBar
  • 导航组件

    • 标签栏 Tabbar
    • 顶部标签栏 TopTabbar
    • 折叠面板 Collapse
    • 课程表 Schedule
  • 布局组件

    • 分割线 Divider
    • 链接 Line
    • 可移动视图 MovableView

yt-movableView 可移动视图组件

属性

属性名类型默认值说明
zIndexnumber2000层级
widthnumber | string'100%'可移动区域宽度
heightnumber | string200可移动区域高度
innerWidthnumber | string'100%'可移动视图宽度
innerHeightnumber | string200可移动视图高度
direction'all' | 'vertical' | 'horizontal' | 'none''all'移动方向限制
inertiabooleantrue是否有惯性
outOfBoundsbooleantrue是否超出边界
xnumber | string0初始 x 轴位置
ynumber | string0初始 y 轴位置
dampingnumber20阻尼系数
frictionnumber3摩擦系数
disabledbooleanfalse是否禁用
scalebooleantrue是否支持缩放
scaleAreabooleantrue是否启用缩放区域
scaleMinnumber0.5最小缩放比例
scaleMaxnumber10最大缩放比例
scaleValuenumber1初始缩放比例
animationbooleantrue是否使用动画

事件

事件名参数说明
change{ x: number, y: number, source: 'touch' | 'touch-out-of-bounds' | 'out-of-bounds' | 'friction' | '' }拖动过程中触发
scaleChange{ x: number, y: number, scale: number }缩放过程中触发

示例

基本可移动视图

<yt-movableView>
  <view class="draggable-box">可拖拽区域</view>
</yt-movableView>

限制移动方向

<yt-movableView direction="vertical">
  <view class="vertical-drag">只能垂直拖拽</view>
</yt-movableView>

<yt-movableView direction="horizontal">
  <view class="horizontal-drag">只能水平拖拽</view>
</yt-movableView>

<yt-movableView direction="none">
  <view class="no-drag">不能拖拽</view>
</yt-movableView>

自定义尺寸

<yt-movableView :width="300" :height="300">
  <view class="custom-area">300x300区域</view>
</yt-movableView>

<yt-movableView width="80vw" height="60vh">
  <view class="responsive-area">响应式区域</view>
</yt-movableView>

初始位置

<yt-movableView :x="100" :y="50">
  <view class="positioned-box">初始位置(100,50)</view>
</yt-movableView>

缩放控制

<yt-movableView :scale="true" :scaleMin="0.5" :scaleMax="3" :scaleValue="1.5">
  <view class="zoomable-box">可缩放视图</view>
</yt-movableView>

<yt-movableView :scale="false">
  <view class="no-zoom-box">不可缩放</view>
</yt-movableView>

禁用拖拽

<yt-movableView :disabled="true">
  <view class="disabled-box">禁用拖拽</view>
</yt-movableView>

<yt-movableView :disabled="isLocked">
  <view class="conditional-drag">{{ isLocked ? '已锁定' : '可拖拽' }}</view>
</yt-movableView>

边界控制

<yt-movableView :outOfBounds="false">
  <view class="bounded-box">不超出边界</view>
</yt-movableView>

<yt-movableView :outOfBounds="true">
  <view class="unbounded-box">可超出边界</view>
</yt-movableView>

惯性控制

<yt-movableView :inertia="true">
  <view class="inertia-box">有惯性</view>
</yt-movableView>

<yt-movableView :inertia="false">
  <view class="no-inertia-box">无惯性</view>
</yt-movableView>

物理参数

<yt-movableView :damping="10" :friction="1">
  <view class="physics-box">低阻尼低摩擦</view>
</yt-movableView>

<yt-movableView :damping="40" :friction="5">
  <view class="physics-box">高阻尼高摩擦</view>
</yt-movableView>

动画控制

<yt-movableView :animation="true">
  <view class="animated-box">带动画</view>
</yt-movableView>

<yt-movableView :animation="false">
  <view class="no-animation-box">无动画</view>
</yt-movableView>

事件处理

<yt-movableView @change="handleDragChange" @scaleChange="handleScaleChange">
  <view class="event-box">拖拽我</view>
</yt-movableView>

<script setup>
  function handleDragChange({ x, y, source }) {
    console.log('位置变化:', { x, y, source })
  }

  function handleScaleChange({ x, y, scale }) {
    console.log('缩放变化:', { x, y, scale })
  }
</script>

图片查看器

<yt-movableView
  :scale="true"
  :scaleMin="0.5"
  :scaleMax="5"
  :scaleValue="1"
  :damping="20"
  :friction="2"
  :animation="true"
  @scaleChange="handleImageZoom"
>
  <image
    :src="currentImage"
    mode="aspectFit"
    class="zoomable-image"
  />
</yt-movableView>

悬浮按钮

<yt-movableView
  :direction="'all'"
  :outOfBounds="false"
  :damping="30"
  :friction="3"
  :width="'100vw'"
  :height="'100vh'"
  :innerWidth="60"
  :innerHeight="60"
  :animation="true"
>
  <view class="floating-button" @click="handleFloatButtonClick">
    <yt-icon name="Plus" :size="24" />
  </view>
</yt-movableView>

可拖拽面板

<yt-movableView
  direction="vertical"
  :outOfBounds="false"
  :damping="25"
  :y="panelY"
  @change="handlePanelDrag"
>
  <view class="draggable-panel">
    <view class="panel-handle"></view>
    <view class="panel-content">
      <!-- 面板内容 -->
    </view>
  </view>
</yt-movableView>

完整示例

<script setup>
  import { ref } from 'vue'

  const imageScale = ref(1)
  const imagePosition = ref({ x: 0, y: 0 })
  const isDragging = ref(false)

  function handleImageDrag({ x, y, source }) {
    imagePosition.value = { x, y }
    isDragging.value = source === 'touch'
  }

  function handleImageZoom({ scale }) {
    imageScale.value = scale
  }

  function resetImage() {
    imageScale.value = 1
    imagePosition.value = { x: 0, y: 0 }
  }
</script>

<template>
  <view class="image-viewer">
    <h3>图片查看器</h3>
    <view class="viewer-container">
      <yt-movableView
        :width="400"
        :height="400"
        :innerWidth="300"
        :innerHeight="300"
        :x="imagePosition.x"
        :y="imagePosition.y"
        :scale="true"
        :scaleValue="imageScale"
        :scaleMin="0.5"
        :scaleMax="3"
        :damping="20"
        :friction="2"
        :animation="true"
        @change="handleImageDrag"
        @scaleChange="handleImageZoom"
      >
        <image
          src="https://example.com/image.jpg"
          mode="aspectFit"
          class="viewer-image"
        />
      </yt-movableView>
    </view>
    <view class="controls">
      <view class="info">
        <text>缩放: {{ imageScale.toFixed(2) }}</text>
        <text>位置: ({{ imagePosition.x }}, {{ imagePosition.y }})</text>
      </view>
      <view class="buttons">
        <yt-button
          @click="resetImage"
          size="small"
        >
          重置
        </yt-button>
      </view>
    </view>
  </view>
</template>
最近更新:: 2026/1/2 20:18
Contributors: CHEEMS
Prev
链接 Line