jQuery - Play video when hover on parent div

前端 未结 4 1262
臣服心动
臣服心动 2020-12-29 16:19

I\'m creating a video gallery consisting of thumbnails that play a short video on hover. I\'ve been able to get them to play while hovering over the video itself, but I nee

4条回答
  •  暖寄归人
    2020-12-29 16:55

    play is not a jQuery function but a function of the DOM element. You therefore need to call it upon the DOM element.

    $(document).ready(function(){
      $(".thumbnail").hover(
        function() {
          $(this).children("video").get(0).play();
        }, function() {
           $(this).children("video").get(0).pause();
            $(this).children("video").get(0).currentTime = 0;
        });
    });
    

    Note: get use for getting the native DOM element from the jQuery selection.

提交回复
热议问题