1

#video-overlay の横にある内部でビデオを再生したいのですが、コードは次のとおりです。

jQuery(".landing-container #video-overlay").hover(function(){
        this.prev().play();
    },function(){
        this.prev().pause();
    });

関数を変更して"video"代わりに使用し、すべて#video-overlayを削除すると、prev()問題ありません..

完璧な解決策は何ですか?#video-overlayホバーでビデオを開始したいと思います。

4

1 に答える 1

1

DOMElementオブジェクトはメソッドをサポートしていません。jQuery メソッド.prev()を使用.prev()するには、要素を jQuery でラップする必要があります。

$("#video-overlay").hover(function() {
   $(this).prev().get(0).play();
              // ^-- Get the first selected DOM Element object from jQuery Collection
              //     for calling `.play` method, assuming the returned element is
              //     a Video or Audio Element object
  }, function() {
     $(this).prev().get(0).pause();
});

DOM Element オブジェクトのpreviousElementSiblingプロパティを使用する ( IE8 以下では機能しません):

$("#video-overlay").hover(function() {
     this.previousElementSibling.play();
  }, function(){
     this.previousElementSibling.pause();
});
于 2013-05-24T20:04:13.747 に答える