【问题标题】:Fancybox iframe gallery in parent page [duplicate]父页面中的 Fancybox iframe 库 [重复]
【发布时间】:2013-01-19 17:08:58
【问题描述】:

可能重复:
call Fancybox in parent from iframe

您好,我的主页上有iframe。里面是一个画廊,当我点击fancybox 图片时,我想在我的父页面中打开图片。我尝试了任何方法,但它只打开一张图片,没有带有下一个和上一个按钮的完整图库。

我的例子:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="imagetoolbar" content="no" />
    <title>FancyBox 1.3.4 | Demonstration</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    <script>
        !window.jQuery && document.write('<script src="jquery-1.4.3.min.js"><\/script>');
    </script>
    <script type="text/javascript" src="./fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
    <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <link rel="stylesheet" type="text/css" href="./fancybox/jquery.fancybox-1.3.4.css" media="screen" />
    <link rel="stylesheet" href="style.css" />

    <script type="text/javascript">
        function readyFancy(){
            $("a#sample").trigger("click");
        }
        function callMe(site){ 
            $("#sample").fancybox({
                'transitionIn'      : 'none',
                'transitionOut'     : 'none',
                'href'              : ''+site+'',
                'autoScale'          : true,
                'onStart'           : function(){$("body").css({'overflow':'hidden'});},
                'onClosed'          : function(){$("body").css({"overflow":"visible"});}
            });
        readyFancy();
        }
    </script>

</head>
<body style="padding: 20px;">
<a href="#" id="sample"></a> <!-- here we set a decoy link for the frame to be triggered-->
<p>Below is an iframe</p>
<iframe src="sample.html" width="300" height="200"> <!--the link of the iframe-->
</body>
</html>

sample.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body >
<div>
<a onClick="parent.callMe('http://localhost/fan/1_b.jpg');" href="#" ><img src="1_s.jpg"></a>
<a onClick="parent.callMe('http://localhost/fan/2_b.jpg');" href="#" ><img src="2_s.jpg"></a>
</div>
</body>
</html>

【问题讨论】:

  • 你把事情复杂化了。检查stackoverflow.com/a/8855410/1055987 确保检查父页面和 iframed 页面(图库)的演示和源代码。
  • 你有下载链接吗,因为我按照说明试了但是不行
  • 对不起,没有链接下载(想法是提供帮助,不是做别人的工作;),demo应该足够了......比较代码
  • 顺便说一句,对parent 的调用可能在localhost 中不起作用,您可能需要在服务器环境中对其进行测试
  • 我不明白,我正在按照说明做所有事情,但是当我点击图片库时它不起作用。什么都不会发生

标签: fancybox


【解决方案1】:

如果您使用 ID 作为选择器 $("#selector").fancybox(); 则切换到类 - $(".selector").fancybox();

【讨论】:

  • 是的,但这并不能解决我的问题
  • 应该。你更新你的jquery了吗?
  • 你不明白我想要什么
猜你喜欢
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 2011-04-09
  • 2011-01-06
相关资源
最近更新 更多