mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-23 05:41:20 -08:00
组件添加add方法
This commit is contained in:
1 parent
1d859e2049
commit
2fcd44e8e7
28 files changed
+303
-328
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { setStyle } from '../utils';
|
||||
import { getPosFromEvent } from './progress';
|
||||
|
||||
export default function thumbnails(option) {
|
||||
return art => ({
|
||||
...option,
|
||||
mounted: $control => {
|
||||
const {
|
||||
option: { thumbnails },
|
||||
template: { $progress },
|
||||
events: { proxy, loadImg },
|
||||
} = art;
|
||||
|
||||
let loading = false;
|
||||
let isLoad = false;
|
||||
|
||||
function showThumbnails(event) {
|
||||
const { width: posWidth } = getPosFromEvent(art, event);
|
||||
const { url, height, width, number, column } = thumbnails;
|
||||
const perWidth = $progress.clientWidth / number;
|
||||
const perIndex = Math.floor(posWidth / perWidth);
|
||||
const yIndex = Math.ceil(perIndex / column) - 1;
|
||||
const xIndex = perIndex % column || column - 1;
|
||||
setStyle($control, 'backgroundImage', `url(${url})`);
|
||||
setStyle($control, 'height', `${height}px`);
|
||||
setStyle($control, 'width', `${width}px`);
|
||||
setStyle($control, 'backgroundPosition', `-${xIndex * width}px -${yIndex * height}px`);
|
||||
if (posWidth <= width / 2) {
|
||||
setStyle($control, 'left', 0);
|
||||
} else if (posWidth > $progress.clientWidth - width / 2) {
|
||||
setStyle($control, 'left', `${$progress.clientWidth - width}px`);
|
||||
} else {
|
||||
setStyle($control, 'left', `${posWidth - width / 2}px`);
|
||||
}
|
||||
}
|
||||
|
||||
proxy($progress, 'mousemove', event => {
|
||||
if (!loading) {
|
||||
loading = true;
|
||||
loadImg(thumbnails.url).then(() => {
|
||||
isLoad = true;
|
||||
});
|
||||
}
|
||||
|
||||
if (isLoad) {
|
||||
setStyle($control, 'display', 'block');
|
||||
showThumbnails(event);
|
||||
}
|
||||
});
|
||||
|
||||
proxy($progress, 'mouseout', () => {
|
||||
setStyle($control, 'display', 'none');
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user