优化公用函数

This commit is contained in:
Harvey Zack committed 2018-10-24 22:02:03 +08:00
1 parent a47d93355b
commit a738f97764
8 files changed
+52 -44

No files matched your search

+11 -1
View File
@@ -1,4 +1,4 @@
import { append } from '../utils';
import { append, clamp, secondToTime } from '../utils';
export default class Progress {
constructor(option) {
@@ -140,6 +140,16 @@ export default class Progress {
: 0;
}
getPosFromEvent(event) {
const { $video, $progress } = this.art.refs;
const { left } = $progress.getBoundingClientRect();
const width = clamp(event.x - left, 0, $progress.clientWidth);
const second = width / $progress.clientWidth * $video.duration;
const time = secondToTime(second);
const percentage = clamp(width / $progress.clientWidth, 0, 1);
return { second, time, width, percentage };
}
set(type, percentage) {
this[`$${type}`].style.width = `${percentage * 100}%`;
if (type === 'played') {