gpt4 book ai didi

jquery - 如何创建到任何 fancybox 框的直接链接

转载 作者:行者123 更新时间:2023-12-03 22:31:14 24 4
gpt4 key购买 nike

我需要当我单击任何使用 fancybox 的内容时,它会生成一个特定的 URL,因此当我将此链接发送给某人时,它会打开我想要的特定框。

例如:fancybox.net/home当我点击第一张图片时,链接仍然fancybox.net/home我希望当我单击图像时,会生成 URL 并显示在地址栏中,例如:fancybox.net/home/imageid=1因此,当我将 fancybox.net/home/imageid=1 发送给某人时,它已经打开了框中的图像

谢谢!

(就像Facebook照片一样,当您点击任何照片时,照片会在一个框中打开,但地址栏会更改为图像链接)

<强>//////更新#1//////

我按照肯尼迪的建议做了,但尝试一小时后我仍然不知道为什么盒子不一样。

看看两者之间的区别:

代码:

<script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
if(window.location.hash) {
$(thisHash).fancybox({
prevEffect : 'none',
nextEffect : 'none',
closeBtn : false,
arrows : true,
nextClick : true,
helpers : {
thumbs : {
width : 80,
height : 80
},
title : {
type : 'inside'
},
buttons : {}
},

afterLoad : function() {
this.title = (this.index + 1) + ' de ' + this.group.length + '<div id="curti"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.google.com.br&amp;send=true&amp;layout=standard&amp;width=45&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:56px; height:24px;" allowTransparency="true"></iframe></div>';
}

}).trigger('click');
}
$('.fancylink').fancybox({
prevEffect : 'none',
nextEffect : 'none',
closeBtn : false,
arrows : true,
nextClick : true,
helpers : {
thumbs : {
width : 80,
height : 80
},
title : {
type : 'inside'
},
buttons : {}
},

afterLoad : function() {
this.title = (this.index + 1) + ' de ' + this.group.length + '<div id="curti"><iframe src="http://www.facebook.com/plugins/like.php?href=http://www.google.com.br&amp;send=true&amp;layout=standard&amp;width=45&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:56px; height:24px;" allowTransparency="true"></iframe></div>';
}

});
}); // ready
</script>

该脚本有什么问题?

最佳答案

首先,您仍然需要在打开 fancybox 的页面中提供指向图像的链接,例如:

<a id="image01" class="fancylink" rel="gallery" href="images/01.jpg" title="image 01">open image 01</a>
<a id="image02" class="fancylink" rel="gallery" href="images/02.jpg" title="image 02">open image 02</a>

...等等

注意,我向每个 anchor 添加了 IDclass,因为我必须通过 URL 定位它们的唯一方法是通过他们的 ID ...一旦我进入页面,该类将用于以常规方式打开 fancybox 中的这些图像,因此我不需要为每个 ID 编写特定的 fancybox 代码。

然后在引用页面上设置此脚本:

<script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
if(window.location.hash) {
$(thisHash).fancybox().trigger('click');
}
$('.fancylink').fancybox();
}); // ready
</script>

然后您可以提供针对每个图像的 URL,例如

http://mydomain.com/page.html#image01

http://mydomain.com/page.html#image02

等等

想要工作演示吗?

http://picssel.com/playground/jquery/targetByID_28jan12.html#image01

http://picssel.com/playground/jquery/targetByID_28jan12.html#image02

注意:此代码适用于 fancybox v1.3.x,因为您使用 fancybox.net 作为引用。

更新#1:如果您想要 fancybox 选项,您需要将它们添加到选择器 IDclass 中,例如:

<script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
if(window.location.hash) {
$(thisHash).fancybox({
padding: 0
// more API options
}).trigger('click');
}
$('.fancylink').fancybox({
padding: 0
// more API options
});
}); // ready
</script>

当然,请为 fancybox v1.3.x 或 2.x 使用正确的选项

关于jquery - 如何创建到任何 fancybox 框的直接链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9028310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com