我使用 Backstretch jquery 作为页面上的幻灯片。我希望能够链接到页面上的单个图像(例如,来自博客文章,甚至来自缩略图视图)。
例如,我希望能够访问 mysite.com/projects/firstproject#3 - 并让它正常加载页面,但从图像 3 开始而不是从开头开始。
这是我的基本回溯代码:
var[images] = [ '/images/project1/1.jpg',
'/images/project1/2.jpg',
'/images/project1/3.jpg'
'/images/project1/4.jpg'
'/images/project1/5.jpg'
]
$(images).each(function() {
$('<img/>')[0].src = this;
});
var index = 0;
$.backstretch(images, {speed: 500});
$('body').data('backstretch').pause();
var identifier = window.location.hash.substring(1) - 1;
//this grabs the anchor at the end, and grabs it as "3" instead of "#3"
//and I need to subtract 1, as backstretch expects the first image id to be 0.
if (identifier > -1 )
$('body').data('backstretch').show(identifier);
};
这有效,但效果不佳。它显示第一个图像,将其余图像加载到后面,然后在完成后移动到所选图像。在包含一堆图像的页面中,这可能是一个相当大的延迟。
有没有更快/更好的方法来做到这一点?