1

ここのこのページを見ると、ほとんどの部分で機能する Youtube ギャラリーのセットアップがあることがわかります。サムネールをクリックすると動画は切り替わるが、右側のテキストがうまく切り替わらない。ビデオの後ろにテキストを読み込んでいるようで、場合によっては右側のテキストを切り替えるのに 2 回クリックする必要があります。

以下の私のjQueryを見て、誰かが問題を特定するのを手伝ってくれませんか?

ありがとう!

<script>
function replaceVideo(id) {
  originalSrc = jQuery("iframe", "#" + id).attr("src");
  autoPlay = originalSrc + "&autoplay=1";
  jQuery("iframe", "#" + id).attr("src", autoPlay);
  video = jQuery(".video-content", "#" + id).html();
  text = jQuery(".video-description").html();
  jQuery(".vid_desc").html(text);
  jQuery(".flex-video").html(video);
  jQuery("iframe", "#" + id).attr("src", originalSrc);
}

jQuery(".video-list li").click(function() {
  id = jQuery(this).attr("id");
  replaceVideo(id);
});

jQuery(window).load(function() {
  if(window.location.search.substring(1)) {
        element = window.location.search.substring(1).split('&');
        if (document.getElementById(element[0])) {
            document.onload = replaceVideo(element[0]);
        }
    }
});
</script>
4

3 に答える 3

0

document.readyコードをハンドラー内にラップします。

$(function(){
jQuery(".video-list li").click(function() {
  id = jQuery(this).attr("id");
  replaceVideo(id);
});
});
于 2013-03-15T07:58:15.783 に答える
0

問題は、表示するテキストを選択する方法にあると思います。

この行

text = jQuery(".video-description").html();

クラス「video-description」ですべての要素を取得しています。おそらく、クリックされたアイテムからビデオの説明を取得したいだけでしょう。次のようなものです:

text = jQuery("#" + id + " .video-description").html();
于 2013-03-15T08:05:47.880 に答える
0

次のコードで修正できました。:-)

<script>
function replaceVideo(id) {
  originalSrc = jQuery("iframe", "#" + id).attr("src");
  autoPlay = originalSrc + "&autoplay=1";
  jQuery("iframe", "#" + id).attr("src", autoPlay);
  video = jQuery(".video-wrap", "#" + id).html();
  jQuery(".flex-video").html(video);
  text = jQuery(".video-description", "#" + id).html();
  jQuery(".vid_desc").html(text);
  jQuery("iframe", "#" + id).attr("src", originalSrc);
}

jQuery(".video-list li").click(function() {
  id = jQuery(this).attr("id");
  replaceVideo(id);
});

jQuery(window).load(function() {
  if(window.location.search.substring(1)) {
        element = window.location.search.substring(1).split('&');
        if (document.getElementById(element[0])) {
            document.onload = replaceVideo(element[0]);
        }
    }
});
</script>
于 2013-03-15T08:17:09.663 に答える