【问题标题】:Jquery Cycle Hash URL from Image Title Attribute来自图像标题属性的 Jquery 循环哈希 URL
【发布时间】:2011-12-10 12:20:12
【问题描述】:

我正在使用 JQuery Cycle 和动态生成的寻呼机导航。我试图弄清楚如何使用图像标题属性中的 window.location.hash 链接到特定幻灯片。我想出了如何使用这个例子(http://jquery.malsup.com/cycle/perma2.html#home)修改插件,但它没有链接。它只是将您送回第一张幻灯片。

我引用了这个 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;
    }
});
});

【问题讨论】:

    标签: jquery jquery-cycle


    【解决方案1】:
    $('#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 上。无需再次“找到”它。

    【讨论】:

    • 谢谢!这是一个如此简单的修复!
    猜你喜欢
    • 2012-03-05
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 2022-01-08
    • 2012-08-21
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    相关资源
    最近更新 更多