【发布时间】:2012-04-27 23:42:01
【问题描述】:
我知道有很多脚本可以显示和隐藏内容,但在我的场景中它们都不适合我。 在此测试页面上http://bloghutsbeta.blogspot.com/2012/04/testing-game-content-issue.html 我在 iframe 中有 flash 游戏,如果你点击 PLAY 按钮或者你不点击仍然会在 Chrome 和 IE 中开始加载 flash 内容(而不是在 firefox 中)。
因此,为了处理这种情况,我想到了使用显示和隐藏内容方法并使用了一些脚本,但它们都没有帮助,即使当我使用它们时,flash 内容仍然用于在 IE 的后端加载和铬合金。 我要的是一个脚本,它在执行“onclick”功能之前不会让 Flash 内容加载。 我知道一个脚本可以执行“LazyLoad”,但它适用于图像,我认为它也不适用于 Flash 内容。
注意:1-提供的链接上有音乐 2- 很抱歉提供 blogspot 链接,但 JsFiddle 不适合居住在阿富汗且速度为 5KBps 的人。
相关标记: 灯箱或模态窗口按钮
<a class="poplight" href="#?w=100%" rel="popup_name"><img alt="play game" class="happybutton" onmouseout="this.style.opacity=0.8;this.filters.alpha.opacity=80" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" src="http://farm5.static.flickr.com/4084/4998558471_27e3985c16_m.jpg" style="opacity: 0.8;" /></a>
在点击上述按钮之前,内容设置为不显示(这实际上在 IE 和 Chrome 中仅在 firefox 中不起作用)
<div class="popup_block" id="popup_name">
<iframe width="100%" height="98%" src="http://files.cryoffalcon.com/bhgames/dressup/Celebrities/Wizard%20Fashion.html" frameborder="0" scrolling="no" allowTransparency="false"
></iframe>
</div>
CSS:
#fade {
display: none;
background: #000;
position: fixed; left: 0; top: 0;
width: 100%; height: 100%;
opacity: .80;
z-index: 9999999;
}
.popup_block{
width: 98.95%; height: 98.2%;
display: none;
padding: 0px;
line-height:1em;
font-size: 1em;
position: fixed;
top: 0px; left: 0px;
z-index: 999999999;
-webkit-box-shadow: 0px 0px 20px #000;
-moz-box-shadow: 0px 0px 20px #000;
box-shadow: 0px 0px 20px #000;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
.close {
height:20px;
float: right;
margin: 0 2px 0 0;
}
JS(实际上是 Jquery)
<script type="text/javascript">
$(document).ready(function(){
//When you click on a link with class of poplight and the href starts with a #
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel'); //Get Popup Name
var popURL = $(this).attr('href'); //Get Popup href to define size
//Pull Query & Variables from href URL
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1]; //Gets the first query string value
//Fade in the Popup and add close button
$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" title="Close It" class="close"><img src="http://files.cryoffalcon.com/bloghuts/images/close%20button.png" alt="Close" width="20" height="20" /></a>');
//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
var popMargTop = ($('#' + popID).height() + 0) / 0;
var popMargLeft = ($('#' + popID).width() + 0) / 0;
//Apply Margin to Popup
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//Fade in Background
$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove();
}); //fade them both out
return false;
});
});
</script>
【问题讨论】:
-
所以问题实际上是:我怎样才能使用 javascript 加载 Flash 内容呢?
-
@twall 很好地加载了 Flash 内容,它没有问题,我所尝试的只是停止它的加载,并让它只有在我们点击播放按钮时才加载。
-
为什么不点击播放按钮时动态添加iframe?
-
嗯,这对我来说听起来是个好主意,你能不能给出一个完整的答案,这样我才能知道该怎么做,因为我在专业上编码有点薄弱,因为我是特许会计师。 (但我喜欢编程)
标签: javascript jquery