2010-05-25 4 views
1

jQuery로 빌드 된 슬라이드 쇼를 가져 오면 일시 중지됩니다. 클릭 한 이미지를 진행하는 미리보기 그룹이 이미지 위에 표시됩니다. 그렇지 않으면 슬라이드 쇼가 모든 이미지를 자동으로 회전합니다. 각 이미지와 관련된 캡션을 확장하고 계약하는 +/-도 있습니다. 미리보기 이미지 중 하나가 클릭되거나 +/-가 표시되면 슬라이드 쇼의 자동 진행을 중지하고 싶습니다. 기본적으로 사용자가 갤러리 내 아무 곳이나 클릭 할 때마다 중지하십시오 (div class = ". homeImg"). 나는 이것이 올바르게 작동하도록하는 데있어 큰 두뇌 방귀를 가지고 있고 조언을 사용할 수 있습니다. 여기에 jQuery를이다 : 당신의 마지막 줄에클릭시 jQuery 슬라이드 쇼 애니메이션 가져 오기

$(document).ready(function() { 

$(".main_image .desc").show(); //Show image info 
$(".main_image .block").animate({ opacity: 0.85 }, 1); //Set Opacity 

//Click and Hover events for thumbnail list 
$(".image_thumb ul li:first").addClass('active'); 

// * Adds a class 'last' to the last li to let the rotator know when to return to the first 
$(".image_thumb ul li:last").addClass('last'); 

$(".image_thumb ul li").click(function(){ 
//Set Variables 
var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image 
var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL 
var imgDesc = $(this).find('.block').html(); //Get HTML of block 
var imgDescHeight = $(".main_image").find('.block').height(); //Calculate height of block 

if ($(this).is(".active")) { //If it's already active, then… 
return false; // Don't click through 
} else { 
//Animate 
$(".main_image img").animate({ opacity: 0}, 800); 
$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 800, function() { 
$(".main_image .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250); 
$(".main_image img").attr({ src: imgTitle , alt: imgAlt}).animate({ opacity: 1}, 250); 
}); 
} 

$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists 
$(this).addClass('active'); //add class of 'active' on this list only 
return false; 

}) .hover(function(){ 
$(this).addClass('hover'); 
}, function() { 
$(this).removeClass('hover'); 
}); 

//Toggle teaser 
$("a.collapse").click(function(){ 
$(".main_image .block").slideToggle(); 
$("a.collapse").toggleClass("show"); 
return false; // added to remove # browser jump 
}); 

// If we are hovering over the image area, pause the clickNext function 
pauseClickNext = false; 
$(".homeImg").hover(
function() { 
pauseClickNext = true; 
}, 
function() { 
pauseClickNext = false; 
} 
); 

// Define function to click the next li 
var clickNext = function(){ 
if(!pauseClickNext) { 
/// find the next li after .active 
var $next_li = $("li.active").next("li"); 
if($("li.active").hasClass("last")){ 
$(".image_thumb ul li:first").trigger("click"); 
} else { 
$next_li.trigger("click"); 
} 
} 
}; 

// Time between image transition 
setInterval(clickNext, 6000); 

}); 
+0

애니메이션의 첫 번째 커플 후에 어떤 코드가 계속 순환하는지 알 수 없습니다. 타이머를 사용하고 있지 않습니까? – arnorhs

답변

2

: var slideTimer = setInterval(clickNext, 6000);

그럼 당신은 애니메이션을 중지 할 때 slideTimer = setInterval(clickNext, 6000);

: 당신은 그냥 다시 설정 다시 시작하려고 할 때 다음 clearInterval(slideTimer);

+0

클릭 이벤트와 어떻게 관련되어 있습니까? 위에서 언급 한 클릭 중 하나가 발생하면 자동화를 중지 할 수 없습니다. 감사! – user279860

+0

캡션 표시/숨기기 기능이 작동하지 않는다고 추가해야합니다. * 편집 - 내 실수, 오타. – user279860

+0

자동 재생을 중지하려는 이벤트에 두 번째 줄을 추가하고 자동 재생을 다시 시작하려는 이벤트의 세 번째 줄을 추가 할 수 있습니다. – mVChr

0

최근에 div 내에서 슬라이드 쇼를 설정하고 재귀를 사용하여 "정지"변수가 "true"로 설정 될 때까지 슬라이드 쇼를 계속 재생합니다. 이 방법을 사용하면 stop = true를 설정할 때마다 슬라이드 쇼 애니메이션이 중단됩니다. onclick 또는 기타 동안 :

var stop = false; 
var i = 0; 

function playGallery(){   
    $("#playerWrapper").fadeOut(1500, function() { 

    if(i<8){ 
     i = i+1; 
    } 
    else{ 
     i = 1; 
    } 

    $("#playerWrapper") 
    .css('background-image','url("images/' + 'brooke' + i + '.jpg' + '")'); 

    if(!stop) { 
     //Use recursion here to keep rotating slides until stop==true 
     playGallery(); 
    } 

    }).fadeIn(1500); 
}