console
canvas = document.getElementById('canvas');
editor = new Editor(canvas);
imageNode = editor.image("http://sf3-ttcdn-tos.pstatp.com/obj/ttfe/video_editor/example.png", {
width: 160,
height: 160,
top: 0,
left: 480
});
videoNode = editor.video("http://sf3-ttcdn-tos.pstatp.com/obj/ttfe/video_editor/example2.mp4", {
width: 640,
height: 360,
crop: {
cropLeft: 0,
cropRight: 320,
cropTop: 0,
cropBottom: 160,
}
});
imageNode.timelineStart(0);
imageNode.timelineStop(10);
videoNode.timelineStart(0);
videoNode.timelineStop(10);
videoNode.connect(editor.output);
imageNode.connect(editor.output);
playButton.onclick = editor.play.bind(editor);
pauseButton.onclick = editor.pause.bind(editor);
let wrapper = document.getElementById('wrapper');
let interactiveBox = editor.initInteractiveBox(wrapper,{
rotatable: true
});
imageNode.on('drag', (res) => {
imageInfo.innerHTML = `图片drag中,left:${res.left}, top:${res.top}`;
})
imageNode.on('resize',(res) => {
imageInfo.innerHTML = `图片resize中,left:${res.left}, top:${res.top}, width:${res.width}, height:${res.height}`;
})
imageNode.on('rotate',(res) => {
imageInfo.innerHTML = `图片rotate中,degree:${res.degree}`;
})
imageNode.on('selected',(res) => {
imageInfo.innerHTML = `图片selected`;
})
videoNode.on('drag', (res) => {
videoInfo.innerHTML = `视频drag中,left:${res.left}, top:${res.top}`;
})
videoNode.on('resize',(res) => {
videoInfo.innerHTML = `视频resize中,left:${res.left}, top:${res.top}, width:${res.width}, height:${res.height}`;
})
videoNode.on('rotate',(res) => {
videoInfo.innerHTML = `视频rotate中,degree:${res.degree}`;
})
videoNode.on('selected',(res) => {
videoInfo.innerHTML = `视频selected`;
})
editImage.onclick = function() {
editor.editNode(imageNode);
}
editVideo.onclick = function() {
editor.editNode(videoNode);
}
editComplete.onclick = function() {
editor.editNode(null);
}
InitVisualisations(editor, 'timeline-canvas', 'current')
<style>
.wrapper {
position: relative;
width: 640px;
height: 360px;
overflow: hidden;
}
</style>
<div class="wrapper" id="wrapper">
<canvas width="640" height="360" id="canvas"></canvas>
</div>
<p>
<button id="playButton">play</button>
<button id="pauseButton">pause</button>
<button id="editImage">编辑图片</button>
<button id="editVideo">编辑视频</button>
<button id="editComplete">编辑完成</button>
</p>
<div class="box">
视频log:<span id="videoInfo"></span>
</div>
<div class="box">
图片log:<span id="imageInfo"></span>
</div>
<p id="current">
</p>
<p>
<canvas id="timeline-canvas" width="640", height="20"></canvas>
</p>
html {
font-family: monospace;
color: #333;
}
#canvas {
width: 640px;
height: 360px;
}
#current {
font-size: 12px;
}
input {
width: 50px;
}
button {
line-height: 1.499;
position: relative;
display: inline-block;
font-weight: 400;
white-space: nowrap;
text-align: center;
background-image: none;
border: 1px solid transparent;
cursor: pointer;
user-select: none;
height: 32px;
padding: 0 15px;
font-size: 14px;
border-radius: 4px;
color: rgba(0,0,0,0.65);
background-color: #fff;
border-color: #d9d9d9;
outline: 0;
transition: all .3s cubic-bezier(.645, .045, .355, 1);
}
button:hover {
color: #40a9ff;
background-color: #fff;
border-color: #40a9ff;
}
.button:active {
color: #096dd9;
background-color: #fff;
border-color: #096dd9;
}
input {
-webkit-appearance: none;
background-color: #fff;
background-image: none;
border-radius: 4px;
border: 1px solid #dcdfe6;
box-sizing: border-box;
color: #606266;
display: inline-block;
font-size: inherit;
height: 32px;
line-height: 32px;
outline: none;
padding: 0 8px;
transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
width: 50px;
}