2013-03-15 5 views
1

this page here을 살펴보면 대부분의 경우 Youtube 갤러리 설정이 있음을 알 수 있습니다. 미리보기 이미지를 클릭하면 동영상이 전환되지만 오른쪽의 텍스트가 제대로 전환되지 않습니다. 그것은 비디오 뒤에 텍스트를 로딩하는 것 같고 어떤 경우 오른쪽의 텍스트를 전환하려면 두 번 클릭해야합니다.JQuery - 클릭시 텍스트가 제대로 작동하지 않음

내 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> 

답변

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> 
0

랩 코드가 document.ready 내부에 있습니다.

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

나는 어떤 텍스트를 표시할지 선택하는 것이 문제라고 생각합니다.

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

이 줄은 클래스 "비디오 설명"에 모든 요소를 ​​잡아입니다. 클릭 한 항목에서 비디오 설명을 가져오고 싶을 수도 있습니다. 그래서 뭔가가 :

text = jQuery("#" + id + " .video-description").html(); 
관련 문제