2010-03-17 5 views
0

Jquery 슬라이드 쇼를 만들고 있습니다. 이 버튼을 클릭하면 큰 이미지가 오버레이로 표시됩니다. 엄지 손가락을 큰 이미지와 일치 시키려면 각 축소판과 큰 이미지에 속성을 추가하고 있습니다. 이 속성에는 각 엄지 손가락과 해당 큰 이미지를 일치시키는 숫자가 포함됩니다. 한 슬라이드 쇼가 페이지에있을 때 작동합니다. 그러나 슬라이드 쇼가 두 개 이상있는 경우 작동하도록하고 싶습니다.Jquery : 1 div 이상의 각 요소 집합에 대한 영향

thumbNo = 0; 
largeNo = 0; 
$('.slideshow_content .thumbs img').each(function() {    
    thumbNo++; 
    $(this).attr('thumbimage', thumbNo); 
    $(this).attr("title", "Enter image gallery"); 
}); 
$('.slideshow_content .image_container .holder img').each(function() { 
    largeNo++; 
    $(this).addClass('largeImage' + largeNo); 
}); 

이 작동 :

여기에 엄지 손가락과 큰 이미지에 속성을 추가하는 코드입니다.

$('.slideshow').each(function() { 
    thumbNo = 0; 
    largeNo = 0; 
    $(this + '.slideshow_content .thumbs img').each(function() {    
     thumbNo++; 
     $(this).attr('thumbimage', thumbNo); 
     $(this).attr("title", "Enter image gallery"); 
    }); 
    $(this + '.slideshow_content .image_container .holder img').each(function() { 
     largeNo++; 
     $(this).addClass('largeImage' + largeNo); 
    }); 
}); 

이 가진 문제는 incrimenting 운영자가 초 동안 재설정되지 않는 것을 ... 나는 내가 각 기능에이 코드를 스틱 수 있다고 생각, 한 페이지에 두 개의 슬라이드 쇼가있을 때 점진 작업을하려면 슬라이드 쇼 div (.slideshow), 그래서 첫 번째 .slideshow div에 번호 1,2,3 등으로 엄지 손가락으로 끝나고 두 번째 .slideshow div에 엄지 손가락으로 번호가 매겨집니다 4,5,6 등. 어떻게해야합니까? 두 번째 .slideshow div의 숫자가 다시 설정되고 다시 1에서 시작 하시겠습니까?

이것은 간결하게 설명하기가 어렵습니다. 누군가가 요지를 얻길 바랍니다. 당신의 각각에서

답변

1

, 레벨을 이동, 그것은 다음과 같이 각각의 슬라이드 쇼에 범위가있어 확인 :

$('.slideshow_content').each(function() { 
    thumbNo = 0; 
    largeNo = 0; 
    $(this).find('.thumbs img').each(function() { 
     $(this).attr('thumbimage', thumbNo++); 
     $(this).attr("title", "Enter image gallery"); 
    }); 
    $(this).find('.image_container .holder img').each(function() { 
     $(this).addClass('largeImage' + largeNo++); 
    }); 
}); 

을이 각 .slideshow_content 블록 내에서 0로 설정하고 그 안에 루프 대신 전체 다음으로 설정 모든 블록을 반복합니다.