你必須模擬你想要關注的元素的點擊。
JQuery允許您使用.click
函數(link)執行此操作。
我舉了一個例子讓它關注組的元素。 第一種方法使用相同的選擇器,的fancybox用於創建組
<script>
$(document).ready(function(){
//get the group of your fancy elements
var fancygroup = $("a[rel=example_group]");
// get the element you want to focus (e.g the first element)
var fancyelem = $(fancygroup.get(1));
// simulate a click
fancyelem.click();
});
</script>
Alternitvly可以指定一個ID要聚焦和模擬點擊它
<p>
Image gallery (ps, try using mouse scroll wheel)<br />
<a rel="example_group" href="./example/9_b.jpg" title="Lorem ipsum dolor sit amet"><img alt="" src="./example/9_s.jpg" /></a>
<a rel="example_group" href="./example/10_b.jpg" title=""><img alt="" src="./example/10_s.jpg" /></a>
<a id="initthis" rel="example_group" href="./example/11_b.jpg" title=""><img alt="" src="./example/11_s.jpg" /></a>
<a rel="example_group" href="./example/12_b.jpg" title=""><img class="last" alt="" src="./example/12_s.jpg" /></a>
</p>
(ID的元素分配給一個THRID元件
,然後直接選擇該元素:
<script>
$(document).ready(function(){
$('#initthis').click();
});
</script>
BR, 斯蒂芬
參考此鏈接..它會幫助你 http://stackoverflow.com/questions/10835849/how-do-i-open-fancybox-via-manual-call-for-a-gallery- in-the-html-not-via-the-jqu – Sathish
@Sathish我已經在我的問題的頂部發布了該鏈接 – arvinsim