【问题标题】:How to implement Fancybox to popup outside an iFrame如何实现 Fancybox 以在 iFrame 外弹出
【发布时间】:2016-07-08 06:34:37
【问题描述】:

我有包含 iframe 的小脚本。 在那个 i 框架中,我通过 Fancybox 配置了一个图像以在 iframe 之外弹出。

当我尝试像他们一样在图像链接上实现that fancybox option 时(参见右侧的 iframe 第 2 页)以弹出 iframe outside 的图像并将其上传到我的服务器 - 它正在工作好吧。

请看这里:My site

但是,当我尝试使该功能在独立版本上运行时(意味着,我希望该功能仅在我的计算机上的 html 文件上运行)我没有得到响应,也没有任何反应。

我认为我错过了 js 和 css 转发部分,但我很确定我已将所有 js 和 css 添加并转发到正确的位置。我真的不知道为什么它不起作用。

我需要的是像这样弹出的图像:

但同样,在独立脚本中什么也不会发生。

这是主页代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Jose Francisco Diaz / picssel.com" />
<title>call fancybox from an iframe in the parent page</title>
<link rel="stylesheet" type="text/css" href="fancybox2.0.4/jquery.fancybox.css" />
<link rel="stylesheet" type="text/css" href="fancybox2.0.4/helpers/jquery.fancybox-buttons.css" />

<script type="text/javascript" src="fancybox2.0.4/helpers/helper.js" id="zZwx_MainScript"></script>
    <link rel="stylesheet" href="fancybox2.0.4/helpers/helper.css" type="text/css" media="all" />

<style type="text/css">
a {outline: 0 none;}
#wrap {
width: 978px;
height: 1000px;
margin: 20px auto;
}
#iframe01 {
width: 450px;
height: 300px;
float: left;
}
#iframe02 {
width: 450px;
height: 300px;
float: right;
}
.spacer {
clear: both;
height: 1px;
display: block;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="fancybox2.0.4/jquery.fancybox.js"></script>
<script type="text/javascript" src="fancybox2.0.4/helpers/jquery.fancybox-buttons.js"></script>
</head>
<body>
<div id="wrap">

    <iframe id="iframe01" src="../pages/7.html"></iframe>
    <iframe id="iframe02" src="iframedPage02_20apr12.html"></iframe>
    <div class="spacer"></div>

</div><!--wrap-->
</body> 
</html>

这是iframe页面代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="fancybox2.0.4/jquery.fancybox.css" />
<link rel="stylesheet" type="text/css" href="fancybox2.0.4/helpers/jquery.fancybox-buttons.css" />

<script type="text/javascript" src="fancybox2.0.4/helpers/helper.js" id="zZwx_MainScript"></script>
    <link rel="stylesheet" href="fancybox2.0.4/helpers/helper.css" type="text/css" media="all" />

<style type="text/css">
#wrap { width: 100%;}
a {outline: 0 none;}
</style>
<script src="jquery.js"></script>
<script type="text/javascript" src="fancybox2.0.4/jquery.fancybox.js"></script>
<script type="text/javascript" src="fancybox2.0.4/helpers/jquery.fancybox-buttons.js"></script>

<script>
/* <![CDATA[ */
$(document).ready(function() {
    $('.imagen').click(function(e){
        e.preventDefault();
parent.$.fancybox([
{href:'img/ebay-home.jpg', title: '01'},
],{
//          href: this.href,
            helpers: {
                overlay: {
                opacity: 0.3
                } // overlay
                //, buttons: {}
            } // helpers
        }); // fancybox
    }); // click
    $('.video').click(function(e){
        e.preventDefault();
        parent.$.fancybox({
            href: this.href,
            width: 560,
            height: 315,
            type: 'iframe',
            helpers: {
                overlay: {
                opacity: 0.3
                } // overlay
            } // helpers
        }); // fancybox
    }); // click
$(".pdf").click(function(){
parent.$.fancybox({
type: 'html',
autoSize: false,
content: '<embed src="'+this.href+'#nameddest=self&page=1&view=FitH,0&zoom=80,0,0" type="application/pdf" height="99%" width="100%" />',
beforeClose: function() {
$(".fancybox-inner").unwrap();
},
            helpers: {
                overlay: {
                opacity: 0.3
                } // overlay
            }
}); //fancybox
return false;
}); //click 
}); // ready
/* ]]> */
</script>
</head>
<body>
<div id="wrap">
    <p>Hello, I am the iframed page 02.</p>
    <p>Open different type of content (imagen, video and/or pdf) in fancybox outside the iframe in the parent page.</p><br />
    <a class="imagen" href="img/ebay-home.jpg">open image gallery</a><br />
    <a class="video" href="http://www.youtube.com/embed/3l8MwU0IjMI?autoplay=1">open youtube video</a><br />
 <a class="pdf" href="images/Fancybox.pdf">open pdf</a>
</div>
</body> 
</html>

这里又是一个现场直播:My site

【问题讨论】:

    标签: javascript jquery html iframe fancybox


    【解决方案1】:

    尝试在 Firefox 浏览器中运行您的独立页面,并尝试从 Apache(localhost) 运行您的页面。它会起作用的。

    【讨论】:

    • 再一次,我希望它在我的计算机上工作,而不是在我的服务器上。
    • iFrame 如果您直接打开它,它将无法工作。最好的方法是您必须在您的机器上安装 Apache 或任何其他 Web 服务器并像 localhost/project1/index.html 一样访问它
    • 为一个脚本在本地安装apache?
    • 通常浏览器将 iFrame 视为安全问题,除非您从 Web 服务器运行它
    【解决方案2】:

    我所需要的只是在 iframe 之外工作的图像弹出窗口。

    我找到了可以解决这个问题的方法,但以另一种方式:

    PureCSS完整教程

    这是一个实时链接:Here

    这是一个配置好的JSfiddle

    这里是html:

           <!-- Lightbox usage markup -->
    <section id="gallery">
        <!-- thumbnail image wrapped in a link -->
        <section class="item">
            <a href="#img1">
              <img src="http://oi67.tinypic.com/23lblu8.jpg">
            </a>
        </section>
    
    </section>
    
    <!-- lightbox container hidden with CSS -->
    <div class="lightbox" id="img1">
      <div class="box">
        <a class="close" href="#">X</a>
        <p class="title">Lorem ipsum dolor sit amet</p>
        <div class="content">
            <img class="imgbox" src="http://oi67.tinypic.com/23lblu8.jpg"> 
            <p class="desc">Lorem ipsum dolor sit amet desc fully</p>
        </div>
    
        <div class="clear"></div>
      </div>
    </div> 
    

    这是css:

    #gallery {
        width:600px;
        }
    
    #gallery a {
        text-decoration:none;
        }
    
    #gallery .item {
        width: 350px; height: 300px; overflow:hidden;
        border: 4px solid #333;
    
        margin: 5px;
        margin-right: -20px;
        }
    
    
    #gallery .item a { 
        overflow: hidden;
        }
    
    #gallery .item a img {
        height: 100%; 
        align-self: center;
        }
    
    .lightbox {
        /** Hide the lightbox */
        display: none;
    
    
        /** Apply basic lightbox styling */
        position: fixed;
        z-index: 9999;
        width: 95%;
        height: 75%;
        top: 0;
        left: 0;
        color:#333333;
        }
    
    .lightbox:target {
        /** Show lightbox when it is target */
        display: block;
        outline: none;
    }
    
    .lightbox .box {
        width: -webkit-min-content;
        width: -moz-min-content;
        width: min-content;
        min-width:500px;
        margin: 0 auto;
        padding:10px 20px 10px 20px;
        background-color:#FFF;
        box-shadow: 0px 1px 26px -3px #777777; 
        }
    
    .lightbox .title {
        margin:0;
        padding:0 0 10px 0px;
        border-bottom:1px #ccc solid;
        font-size:22px;
        }
    
    .lightbox .content {
        display:block;
        position:relative;
        }
    
    .imgbox {max-width: 830px; }
    
    
    .lightbox .content .desc {
        z-index:99;
        bottom:0;
        position:absolute;
        padding:10px;
        margin:0 0 4px 0;
        background:rgba(0,0,0,0.8);
    
        color:#fff;
        font-size:17px;
        opacity:0;
        transition: opacity ease-in-out 0.5s;
        }   
    
    .lightbox .content:hover .desc  {
        opacity:1;
    }
    
    .lightbox .next,
    .lightbox .prev,
    .lightbox .close {
        display:block;
        text-decoration:none;
        font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size:22px;
        color:#858585;
        }
    
    .prev {
        float:left;
        }
    
    .next, .close {
        float:right;
        }
    
        .clear {
            display:block;
            clear:both;
            }
    

    现在我可以在 iframe 之外弹出图像了。

    不需要服务器端。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2020-03-11
      • 1970-01-01
      • 1970-01-01
      • 2012-02-29
      • 1970-01-01
      相关资源
      最近更新 更多