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

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

问题描述

我需要当我点击任何使用fancybox的东西时,它会生成一个特定的URL,所以当我把这个链接发送给某人时,它会打开我想要的特定框.

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

谢谢!

(就像facebook的照片,当你点击任何照片时,照片会在一个框中打开,但地址栏会变成图片链接)

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

我按照 JFK 的建议做了,但尝试了一个小时后,我仍然不知道为什么盒子不一样.

看看两者的区别:

代码:

那个脚本有什么问题?

解决方案

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

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

...等

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

然后在引用页面设置这个脚本:

然后您可以提供针对每个图像的 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 作为参考.

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

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

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.

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

Thanks!

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

////// UPDATE #1 //////

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

Look the diference between:

the code:

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

What's wrong in that script?

解决方案

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>

... etc.

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

or

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

etc.

wanna working demo?

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

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

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

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>

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

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

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