2011-10-18 9 views
5

動的に生成されるポケットベルナビゲーションでJQuery Cycleを使用しています。 image title属性から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-jquerycycle)を参照しましたが、既存のページャーのナビゲーションであり、オンザフライで生成されるものではありません。私はまだJqueryを勉強していないので、どんな指導にも感謝しています!ここで

は、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; 
}); 

あなたはIMG-DOM上に既にある

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

でなければなりません。もう一度 "見つける"必要はありません。

+0

ありがとうございます!それはとても簡単な修正でした! – hootnanny