繁体   English   中英

在没有手动打开的情况下从iframe调用父级中的Fancybox

[英]call Fancybox in parent from Iframe with no manual open

我想我可以在这里得到答案-> 从iframe调用父级的Fancybox,演示页面显示了我真正想要的( http://www.picssel.com/playground/jquery/fancyboxFromIframe_16Jan12.html ),但是问题是我没有相同的脚本...

代替(我猜这是手动打开):

$(".video").click(function() {
    $.fancybox({
        'padding'       : 0,
        // more options (v2.x) etc

我这样称呼照片:

$(document).ready(function() {
    $(".fancybox-thumbs").fancybox({
    padding: 0,
    // etc

我试图像这样更改代码(基于答案和演示):

$(document).ready(function() {
    parent.$(".fancybox-thumbs").fancybox({
    padding: 0,
    // etc

...但是它不起作用。 有人可以告诉我如何更改iframe中的拇指,打开父页面上的图像并调整为屏幕尺寸的代码吗?

提前致谢 !

我在论坛上从我自己的问题中找到了答案,不幸的是从来没有(!)...我与您分享,也许对某人有帮助:

1首先,我将.css和.js文件链接到父html和iframe html。

2我的父母html

<body>
<div id="more">
<div class="container">
        <div id="sensuality-div">
            <iframe id="sensuality-frame" src="http://www.igorlaszlo.com/sensuality.html" width="100%" height="100%" style="overflow:hidden;height:100%;width:100%;" scrolling="no" allowTransparency="true" frameborder="0" sandbox="allow-same-origin allow-forms allow-scripts" ></iframe>
        </div>
    </div>
</div>
</body>

3我的iframe html

<body id="sensuality-body">

    <div class="view view-add"> 
        <img src="http://www.igorlaszlo.com/uploads/thumbs/41.jpg" alt="Thierry Mercier 16" /> 
        <div class="mask">
            <a href="http://www.igorlaszlo.com/uploads/images/41.jpg" class="fancybox-thumbs" rel="group1" alt="Model : Thierry Mercier - 2009 June" title="34 Dance in the Dark"> 
                <h4>Dance in the Dark</h4> 
            <p>Model : Thierry Mercier</p> 
            <info>Click for zoom</info>
            </a> 
        </div> 
    </div>

    <div class="view view-add"> 
        <img src="http://www.igorlaszlo.com/uploads/thumbs/41.jpg" alt="Thierry Mercier 16" /> 
        <div class="mask">
            <a href="http://www.igorlaszlo.com/uploads/images/41.jpg" class="fancybox-thumbs" rel="group1" alt="Model : Thierry Mercier - 2009 June" title="34 Dance in the Dark"> 
                <h4>Dance in the Dark</h4> 
            <p>Model : Thierry Mercier</p> 
            <info>Click for zoom</info>
            </a> 
        </div> 
    </div>

</body>        

4以下是我调用fancybox的原始代码(不是手动打开)(我在父页面和iframe页面上都有它):

<script>
$(document).ready(function() {
    $(".fancybox-thumbs").fancybox({
    padding: 0,

    openEffect : 'elastic',
    openSpeed  : 150,

    closeEffect : 'elastic',
    closeSpeed  : 150,

    closeClick : true,

    prevEffect : 'elastic',
    nextEffect : 'elastic',

    closeBtn  : true,
    arrows    : true,
    nextClick : true,

    beforeShow: function () {
        this.title = $(this.element).attr('title');
        this.title = '<h3>' + this.title + '</h3>' + $(this.element).attr('alt') + '<br />';
    },

            afterShow: function() {
    },

            helpers : {
        title : { type: 'inside' }
    }
    });
    });
</script>

5骇客:我将找到的代码( http://www.dynamicdrive.com/forums/archive/index.php/t-56981.html )与我的代码合并,并在iframe页面上添加了附加脚本:

<script type="text/javascript">
jQuery(function($) {
    if(top !== window){
        var $$ = parent.jQuery;
        $$('#sensuality-div').html($('#sensuality-body').html()).find('a').fancybox({
            padding: 0,

        openEffect : 'elastic',
        openSpeed  : 150,

        closeEffect : 'elastic',
        closeSpeed  : 150,

        closeClick : true,

        prevEffect : 'elastic',
        nextEffect : 'elastic',

        closeBtn  : true,
        arrows    : true,
        nextClick : true,

        beforeShow: function () {
            this.title = $(this.element).attr('title');
            this.title = '<h3>' + this.title + '</h3>' + $(this.element).attr('alt') + '<br />';
        },

        afterShow: function() {
        },

        helpers : {
            title : { type: 'inside' }
        }
        });
        $("#sensuality-body a").click(function(e){
            $$('#' + this.class).click();
        });
    } 
    else {
        $("#sensuality-body a").fancybox({
        padding: 0,

        openEffect : 'elastic',
        openSpeed  : 150,

        closeEffect : 'elastic',
        closeSpeed  : 150,

        closeClick : true,

        prevEffect : 'elastic',
        nextEffect : 'elastic',

        closeBtn  : true,
        arrows    : true,
        nextClick : true,

        beforeShow: function () {
            this.title = $(this.element).attr('title');
            this.title = '<h3>' + this.title + '</h3>' + $(this.element).attr('alt') + '<br />';
        },

        afterShow: function() {
        },

        helpers : {
            title : { type: 'inside' }
        }
        });
    }
});
</script>

也许您可以使其变得更容易,也许我添加了很多不必要的代码,但我知道它可以正常工作...

我看到很多人正在寻找解决此类问题的方法,希望对您有所帮助!

很快您将可以在www.igorlaszlo.com上看到它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM