当前位置: 代码网 > it编程>编程语言>Javascript > 使用Vue实现带拖动和播放功能的时间轴

使用Vue实现带拖动和播放功能的时间轴

2024年05月18日 Javascript 我要评论
带拖动和播放功能的时间轴timeline-slider-vuedemogithub环境node v12.20.0npm 6.14.8installnpm install --save timeline

带拖动和播放功能的时间轴

timeline-slider-vue

demo

github

环境

  • node v12.20.0
  • npm 6.14.8

install

npm install --save timeline-slider-vue

usage

main.js

import timelineslidervue from 'timeline-slider-vue'
import 'timeline-slider-vue/lib/timeline-slider-vue.css'
vue.use(timelineslidervue)

```vue
    <timelineslidervue
      :date="date"
      :mask="mask"
      :mark-date="markdate"
      :lock-date="lockdate"
      :play="play"
      :play-speed="playspeed"
      @change="handlechange"
      @input="handleinput">
      <div
        slot="slidercontent"
        slot-scope="scope">
        {{ scope.data }}
      </div>
    </timelineslidervue>

使用示例

<template>
	<div id="app">
		<timelineslidervue
			:date="date"
			:mask="mask"
			:mark-date="markdate"
			:lock-date="lockdate"
			:play="play"
			:play-speed="playspeed"
			@change="handlechange"
			@input="handleinput"
		>
			<div slot="slidercontent" slot-scope="scope">
				{{ scope.data }}
			</div>
		</timelineslidervue>
	</div>
</template>

<script>
export default {
	data() {
		return {
			playspeed: 1000, // 播放速度
			play: false, // 自动播放
			lockflag: false,
			markflag: false,
			lockdate: [], // 锁定的日期(滑动结束时自动跳到指定的日期)
			markdate: [], // 做标记的日期
			mask: true,
			date: '2022-06-01',
		}
	},
	methods: {
		handleinput(date, value) {
			console.log('input', date, value)
		},
		handlechange(date, value) {
			console.log('change', date, value)
		},
	},
}
</script>

竖向模式

    <timelineslidervue
      vertical
      height="240px"
      :max-value="100"
      :min-value="0"
      :init-value="40"
      @change="handlechange"
      @input="handleinput"
    >
      <div slot="slidercontent" slot-scope="scope">
        <div>{{ scope.value }}</div>
      </div>
    </timelineslidervue>

available props

参数类型默认值说明
verticalbooleanfalse竖向模式(只有滑块功能样式,没有日期等功能)
initvaluenumber0v-model 绑定的初始值(仅在 vertical = true 时生效)
minvaluenumber0最小值(仅在 vertical = true 时生效)
maxvaluenumber100最大值(仅在 vertical = true 时生效)
datestring当日yyyy-mm-dd 格式的日期,根据传入的日期,设置滑块的位置
maskbooleantrue拖动过程中是否显示遮罩层
mark-datearray[]一些特殊日期标注,例如 [‘2022-03-08’, ‘2022-06-18’, ‘2022-11-11’]
lock-datearray[]锁定的日期,只能在指定日期下切换,当滑块拖动到其他位置,自动跳到离指定日期最近的日期处例如 [‘2022-03-08’, ‘2022-06-18’, ‘2022-11-11’]
playbooleanfalse播放
playspeednumber1000播放速度,同 setinterval milliseconds 参数

slot

参数说明
slidercontent滑块内容

events

事件名称说明回调参数
change值改变时触发(使用鼠标拖拽时,只在松开鼠标后触发)改变后的值
input数据改变时触发(使用鼠标拖拽时,活动过程实时触发)改变后的值

project setup

yarn install

compiles and hot-reloads for development

yarn serve

compiles and minifies for production

yarn build

lints and fixes files

yarn lint

到此这篇关于使用vue实现带拖动和播放功能的时间轴的文章就介绍到这了,更多相关vue时间轴内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com