daily-share icon indicating copy to clipboard operation
daily-share copied to clipboard

视频墙的优化方案

Open yaogengzhu opened this issue 9 months ago • 1 comments

鼠标移入加载视频,移除取消视频加载


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');
}

yaogengzhu avatar May 11 '24 07:05 yaogengzhu