,我發現我自己在論壇上的問題的答案,可惜從來沒有...我跟大家分享一下,也許它可以幫助的人:
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
如果您'的console.log(父$);'它記錄它的存在,或者說,它是不確定的? –
Dave,對不起,我不是javascript的專家,你能告訴我如何將它整合到整個代碼中嗎? –
@戴夫斯坦 如果你想過:。 '$(文件)。就緒(函數(){ \t的console.log(父$); \t $( 「的fancybox-拇指」)的fancybox( { \t padding:0,' ...它加載圖片但不起作用,它以正常方式加載而不考慮父頁面屏幕 –