如何在页面上实现深度链接,以便当用户从外部链接访问该页面时,启动fancybox模式。我是JS/Jquery的新手
发布于 2012-02-10 21:47:26
今天早上我也在找同样的东西,我找到了你的问题,还有一个论坛帖子上有答案。
(function()
{
var qs = location.search.slice( 1 ),
params = qs.match( /&?ab=(\d+)\|(\d+)/ );
if( params )
page( Number( params[ 1 ] ), Number( params[ 2 ] ) );
})();“然后,如果您链接到该页面,并在此表单中传递两个数字参数:
concert.html?ab=1|5
当页面加载时,它应该具有调用page(1,5)的惊人效果。“
http://www.webdeveloper.com/forum/showthread.php?t=247899
希望它能帮到我--它帮助了我。:)
发布于 2012-10-20 22:42:22
我刚刚用fancybox2和url哈希为自己解决了这个问题。
您可以使用Fancybox回调来设置和取消设置哈希。
我在img标记中使用了数据属性来存储img标识符。
然后,您可以在页面加载时检查url中的散列,获取索引,并使用给定的索引打开fancybox。
var option = {
afterLoad: function(links) {
var title = links.element.attr('data-my-img');
location.hash = title;
},
afterClose: function() {
location.hash = '';
}
},
hash = location.hash.substr(1),
gallery = $('.fancybox');
if(hash.length > 0){
//id
var i = null;
gallery.each(function(index) {
var o = $(this).attr('data-my-img');
if($(this).attr('data-my-img') == hash){
i = index;
return;
}
});
if(i != null){
option.index = i;
$.fancybox.open(gallery, option);
}
}
gallery.fancybox(option); https://stackoverflow.com/questions/9152751
复制相似问题