来自图像标题属性的Jquery循环哈希URL

来自图像标题属性的Jquery循环哈希URL,jquery,jquery-cycle,Jquery,Jquery Cycle,我使用jquerycycle和动态生成的寻呼机导航。我试图找出如何使用图像标题属性中的window.location.hash链接到特定幻灯片。我通过这个例子了解了如何修改插件直到现在http://jquery.malsup.com/cycle/perma2.htmlhome,但它没有链接。它只是将您送回第一张幻灯片 我引用了这个stackoverflow支持线程http://stackoverflow.com/questions/4969752/display-anchor-instead-o

我使用jquerycycle和动态生成的寻呼机导航。我试图找出如何使用图像标题属性中的window.location.hash链接到特定幻灯片。我通过这个例子了解了如何修改插件直到现在http://jquery.malsup.com/cycle/perma2.htmlhome,但它没有链接。它只是将您送回第一张幻灯片

我引用了这个stackoverflow支持线程http://stackoverflow.com/questions/4969752/display-anchor-instead-of-index-in-url-with-jquery-cycle,但他们使用的是现有的寻呼机导航,而不是动态生成的导航。我对学习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;
    }
});
});
应该是

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

您已经在img DOM上了。不用再找了。

谢谢!这是一个如此简单的修复!
$('#slide img').each(function(i) {
    h = $(this).attr('title');
    hashes[h] = i;
});