index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { useCallback, useEffect, useRef } from 'react'
  2. import styles from './index.module.scss'
  3. import classNames from 'classnames'
  4. import { domDelOwnFu } from '@/utils/utilsSome'
  5. import BtnRight from '../BtnRight'
  6. type Props = {
  7. isShow: boolean
  8. src: string
  9. parentFu: () => void
  10. noBtn?: boolean //没有跳过按钮
  11. }
  12. function CatVideo({ isShow, src, parentFu, noBtn }: Props) {
  13. const videoRef = useRef<HTMLVideoElement>(null)
  14. useEffect(() => {
  15. if (isShow) {
  16. setTimeout(() => {
  17. if (videoRef.current) videoRef.current.play()
  18. }, 100)
  19. }
  20. }, [isShow])
  21. const playEndFu = useCallback(() => {
  22. parentFu()
  23. // 0.5s之后删除过度视频
  24. setTimeout(() => {
  25. domDelOwnFu('#CatVideo')
  26. }, 500)
  27. }, [parentFu])
  28. return (
  29. <div id='CatVideo' className={classNames(styles.CatVideo, isShow ? '' : styles.CatVideoHide)}>
  30. <video
  31. ref={videoRef}
  32. playsInline
  33. muted
  34. webkit-playsinline='true'
  35. x5-video-player-type='h5'
  36. onEnded={playEndFu}
  37. >
  38. <source type='video/mp4' src={src} />
  39. Your browser does not support the video tag.
  40. </video>
  41. {/* 右下角的跳过按钮 */}
  42. {noBtn ? null : <BtnRight imgName='skip' clickSon={() => playEndFu()} title='跳过' />}
  43. </div>
  44. )
  45. }
  46. const MemoCatVideo = React.memo(CatVideo)
  47. export default MemoCatVideo