2011-10-18 2 views
5

동적으로 생성 된 호출기 탐색 기능과 함께 JQuery Cycle을 사용하고 있습니다. 이미지 제목 특성에서 window.location.hash를 사용하여 특정 슬라이드에 연결하는 방법을 파악하려고합니다. 이 예제 (http://jquery.malsup.com/cycle/perma2.html#home)를 사용하여이 시점까지 플러그인을 수정하는 방법을 알았지 만 연결되지 않습니다. 첫 번째 슬라이드로 다시 보냅니다.이미지 제목 속성의 Jquery Cycle 해시 URL

이 stackoverflow 지원 스레드 (http://stackoverflow.com/questions/4969752/display-anchor-instead-of-index-in-url-with-jquery-cycle)를 참조했지만 기존 호출기 내비게이션 (Pager Navigation). 나는 Jquery를 배우는 것에 아직 익숙하지 않으므로, 어떤 지침도 감사하겠습니다!

$(function() { 
var h, 
    hash = window.location.hash, 
    hashes = {}, 
    index = 0; 

$('#slide img').each(function(i) { 
    h = $(this).find('img').attr('title'); 
    hashes[h] = i; 
}); 

if (hash) 
    index = hashes[hash.substring(1)] || index; 

$('#slide').cycle({ 
    fx:  'fade', 
    startingSlide: index, // <-- don't forget this! 
    speed: 'fast', 
    timeout: 0, 
    activePagerClass: 'active', 
    pager: '.timeline', 
    pagerAnchorBuilder: function(idx, slide) { 
     // return selector string for existing anchor 
     return '.timeline li:eq(' + idx + ') a'; 
    }, 
    after: function(curr,next,opts) { 
     h = $(this).find('img').attr('title'); 
     window.location.hash = h; 
    } 
}); 
}); 

답변

3
$('#slide img').each(function(i) { 
    h = $(this).find('img').attr('title'); 
    hashes[h] = i; 
}); 

$('#slide img').each(function(i) { 
    h = $(this).attr('title'); 
    hashes[h] = i; 
}); 

당신은 IMG-DOM에 이미 있어야한다 :

다음은 jQuery를 스크립트입니다. 다시 "찾을"필요가 없습니다.

+0

고마워요! 그건 아주 간단한 수정이었습니다! – hootnanny