fancybox手动调用特定目标
我从fancybox实现了手动脚本:
$("#manual2").click(function() { $.fancybox([ 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'http://sofzh.miximages.com/jquery/photo_unavailable.png', { 'href' : 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' } ], { 'padding' : 0, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'image', 'changeFade' : 0 }); });
现在我想知道,如果可以通过点击链接直接看到特定的图片。 (例如直接到第二个第三张图片)。
要从第二张幻灯片开始,只需将'index' : 1,
添加到您的选项json中。
这是完全写出来的……
$("#manual2").click(function() { $.fancybox([ 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'http://sofzh.miximages.com/jquery/photo_unavailable.png', { 'href' : 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' } ], { 'index' : 1, 'padding' : 0, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'image', 'changeFade' : 0 }); });
必须具有1.3.1或更高版本。 有关更多详细信息,请参阅Fancybox API: http ://fancybox.net/api
更新:您询问是否可以从链接本身设置索引,答案是肯定的。 只需确保使用自定义data-
属性(例如, data-index="2"
)设置要打开的幻灯片,然后使用此代码而不是之前的代码…
$("#manual2").click(function() { $.fancybox([ 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'http://sofzh.miximages.com/jquery/photo_unavailable.png', { 'href' : 'http://sofzh.miximages.com/jquery/photo_unavailable.png', 'title' : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit' } ], { 'index' : $(this).data('index'), 'padding' : 0, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'image', 'changeFade' : 0 }); });