daily-share
daily-share copied to clipboard
视频墙的优化方案
鼠标移入加载视频,移除取消视频加载
function _handleVideoHover() {
const className = `.item[data-type='2']`;
function playVideo() {
const videoElement = $(this).find('video.hover-play').get(0);
if (videoElement && typeof videoElement.play === 'function') {
if (!$(videoElement).data('original-src')) {
$(videoElement).data('original-src', $(videoElement).attr('src'));
}
$(videoElement).attr('src', $(videoElement).data('original-src'));
videoElement.play()
.then(() => {
})
.catch(error => {
});
}
}
function pauseVideo() {
const videoElement = $(this).find('video.hover-play').get(0);
if (videoElement && typeof videoElement.pause === 'function') {
videoElement.pause();
$(videoElement).attr('src', '');
}
}
$('body')
.on('mouseover', className, playVideo)
.on('mouseout', className, pauseVideo);
console.log('video ready');
}