如何创建任何fancybox框的直接链接 [英] How to create a direct link to any fancybox box

查看:88
本文介绍了如何创建任何fancybox框的直接链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need that when I click in anything that uses fancybox it generates a specific URL for that, so when I send this link to someone, it opens the specific box I want.

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

For example: fancybox.net/home when I click in the first image, the link still fancybox.net/home I want that when I click in the image, the URL is generated and appears in address bar like: fancybox.net/home/imageid=1 so when i send fancybox.net/home/imageid=1 to someone it already opens the image in the box

谢谢!

(就像Facebook照片,当你点击任何照片时,照片打开方框但地址栏更改为图片链接)

(It is like facebook photos, when you click in any photo, the photo opens in a box but the address bar changes to the image link)

//////
更新#1
//////

我做了JFK的建议,但经过一个小时的尝试,我仍然不知道为什么盒子不一样。

I did what JFK suggested but after one hour trying i still don't know why the boxes aren't the same.

看看之间的差异:

代码:

<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的页面中找到你的图像的链接,如:

First you still need to have links to your images in the page that opens fancybox like:

<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>

...等。

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

Notice that I am adding both an ID and a class to each anchor since the only way I have to target them via URL is through their ID ... the class will be used to open those images in fancybox in a regular way once I am on the page so I don't need to write a specific fancybox code for each ID.

然后在参考页面上设置此脚本:

then set this script on the page of reference:

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

然后你可以提供针对每个图像的网址,例如

then you can provide the URL that targets each image like

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作为参考。

NOTE: This code is for fancybox v1.3.x since you used fancybox.net as reference.

UPDATE#1 :如果你想要fancybox选项,你需要在两个选择器中添加它们 ID class 喜欢:

UPDATE #1: if you want fancybox options you need to add them in both selectors ID and class like:

<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使用正确的选项

Of course, use the right options either for fancybox v1.3.x or 2.x

这篇关于如何创建任何fancybox框的直接链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆