mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-19 19:51:20 -08:00
优化公用函数
This commit is contained in:
1 parent
a47d93355b
commit
a738f97764
8 files changed
+52
-44
No files matched your search
@@ -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') {
|
||||
|
||||
Reference in new issue
Block a user