2013-08-31 55 views
0

我想我可以在這裏得到答案 - >call Fancybox in parent from iframe和演示頁面顯示真正我想要的(http://www.picssel.com/playground/jquery/fancyboxFromIframe_16Jan12.html),但問題是,我沒有相同的腳本。 ..打電話給Fancybox從iframe的父母沒有手動打開

而不是(我猜這是手動開啓):

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

我所說的圖片是這樣的:

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

我想陳GE我這樣的代碼(基於答案&演示):

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

...但它不工作。有人可以告訴我,我應該如何更改我的代碼,在iframe中的拇指,打開父頁上的圖像,調整到屏幕?

在此先感謝! (!)

+0

如果您'的console.log(父$);'它記錄它的存在,或者說,它是不確定的? –

+0

Dave,對不起,我不是javascript的專家,你能告訴我如何將它整合到整個代碼中嗎? –

+0

@戴夫斯坦 如果你想過:。 '$(文件)。就緒(函數(){ \t的console.log(父$); \t $( 「的fancybox-拇指」)的fancybox( { \t padding:0,' ...它加載圖片但不起作用,它以正常方式加載而不考慮父頁面屏幕 –

回答

0

,我發現我自己在論壇上的問題的答案,可惜從來沒有...我跟大家分享一下,也許它可以幫助的人:

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

+1

您將很快就能在www.igorlaszlo.com上看到它 –