【发布时间】: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