1.0.1 • Published 1 year ago

image-time-line v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

视频编辑帧功能,同抖音编辑视频帧功能,附带有拖动插件

使用方法

npm安装

npm i image-time-line

imageTimeLine方法使用

1.引入

import { imageTimeLine } from "image-time-line";

2.视频切片使用示例

import { videoSlice } from "video-slice";
import { imageTimeLine }  from "image-time-line";
const inputDom = document.getElementById("chooseFile");
const imgsDom = (document.getElementById("imgs")) as HTMLElement;
const list:Array<string> = [];
inputDom?.addEventListener("change",(res)=>{
    const input:any = res.target
    const video:any = document.getElementById("app");
    if(video){
        //方法一:切片完成再添加
        const videoToImg = videoSlice({
            width:100,
            file:input.files[0],
            success:()=>{
                video.src = videoToImg.getSrc();
                //快速切片
                videoToImg.fastStart();
            },
            backImgFn:(res)=>{ //切片返回的地方
                
            },
            finish:()=>{
                console.log("完成",list)
                const timeLineObj = imageTimeLine({
                    video,
                    imgsDom,
                    imgs:list,
                    total:list.length,
                })
            }
        })
        //方法二:先占位然后一次性全部添加
        const timeLineObj = imageTimeLine({
            total:7,
            placeholderImg:'https://campus.wo.cn/cos/static/my/noData.png',
            video,
            imgsDom,
        })
        const videoToImg2 = videoSlice({
            width:100,
            file:input.files[0],
            success:()=>{
                video.src = videoToImg2.getSrc();
                //快速切片
                videoToImg2.fastStart();
            },
            backImgFn:(res)=>{ //切片返回的地方
                list.push(res);
                
            },
            finish:()=>{
                console.log("完成",list)
                timeLineObj.changeAll(list)
            }
        })
        //方法三:不知道图片张数,一张一张的添加
        const timeLineObj3 = imageTimeLine({
            video,
            imgsDom,
        })
        const videoToImg3 = videoSlice({
            width:100,
            file:input.files[0],
            success:()=>{
                video.src = videoToImg3.getSrc();
                //快速切片
                videoToImg3.fastStart();
            },
            backImgFn:(res)=>{ //切片返回的地方
        
                // 方法三:一张一张的添加
                timeLineObj3.add(res);
            },
            finish:()=>{
                console.log("完成")
            }
        })
        
    }
})

参数结构

参数说明类型参数是否必传
video视频dom节点HTMLVideoElement
imgsDom图片列表显示的domHTMLElement
total图片的总数number
imgs需要显示的图片数组Array
placeholderImg默认的占位图片地址string
changeScale拖动指针会触发该函数,返回整体的移动占比(scale:number)=>void

方法说明

方法名称说明类型参数说明
move设置指针位移(scale:number)=>voidscale:位移比例,最大1
getImgs返回全部图片()=>Array-
add原有基础上添加图片(imgs:string|Array)=>voidimgs:图片或者图片数组
changeIndex替换指定的index图片(img:string,index?:number)=>voidimg:图片,index:需要替换的index,如果没传,就自动匹配下一个需要替换的占位图片
changeAll直接替换全部图片(imgs:Array)=>voidimgs:图片数组
remove指定删除第几张图片(index:number)=>void-
clear清除全部图片()=>void-
clearPlaceholderImg清除全部占位图片()=>void-

拖动插件addMouseListener方法使用

1.引入

import { addMouseListener } from "image-time-line";

2.视频切片使用示例

import { addMouseListener } from "image-time-line";
const mouseObj = addMouseListener(Dom,{
        type:'x',
        changeStatus:(res)=>{
          console.log(res)
        },
        change:(res)=>{
          console.log(res)
        }
      });

拖动插件参数结构

参数说明类型参数是否必传
dom需要拖动的节点HTMLElement
type移动方向默认x、y轴,可传"x"或"y"
left初始的leftnumber
top初始的topnumber
maxX最大x轴位移number
maxY最大y轴位移number
change位移变化触发函数(value:{x?:number,y?:number})=>void
changeStatus拖动状态变化触发函数(status:string)=>void

拖动插件方法说明

方法名称说明类型参数说明
move移动比例(value: Record<string, number>)=>voidvalue:{ x:10, y:10 },x轴和y轴需要移动的值 单位px