Javascript Js显示和隐藏函数
我知道有很多脚本可以显示和隐藏内容,但在我的场景中没有一个适合我。 在这个测试页面上 我在iframe中有flash游戏,如果你点击PLAY按钮或不点击静止按钮,flash内容将开始在Chrome和IE中加载(不是在firefox中) 因此,为了应对这种情况,我考虑使用显示和隐藏内容的方法,并使用了一些脚本,但它们都没有帮助,因为即使在我使用它们时,flash内容仍然用于在IE和Chrome的后端加载。 我想要的是一个脚本,它在执行“onclick”功能之前不会让flash内容加载。 我知道有一个脚本可以实现这种“懒散加载”,但它是用于图像的,我不认为它也适用于flash内容 注意:1-提供的链接上有音乐 2-很抱歉提供blogspot链接,但是对于生活在阿富汗的5KBps的人来说,JSFIDLE不是一个选项 相关标记: 灯箱或模式窗口的按钮Javascript Js显示和隐藏函数,javascript,jquery,Javascript,Jquery,我知道有很多脚本可以显示和隐藏内容,但在我的场景中没有一个适合我。 在这个测试页面上 我在iframe中有flash游戏,如果你点击PLAY按钮或不点击静止按钮,flash内容将开始在Chrome和IE中加载(不是在firefox中) 因此,为了应对这种情况,我考虑使用显示和隐藏内容的方法,并使用了一些脚本,但它们都没有帮助,因为即使在我使用它们时,flash内容仍然用于在IE和Chrome的后端加载。 我想要的是一个脚本,它在执行“onclick”功能之前不会让flash内容加载。 我知道有一
<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>
JS(实际上是Jquery)
您应该尝试这样的方法,在单击按钮后立即加载帧:
$(document).ready(function(){
$('a.poplight[href^=#]').click(function() {
$('<iframe/>')
.attr('frameborder', 0)
.attr('allowTransparency', false)
.attr('scrolling', 'no')
.attr('width', '100%')
.attr('height', '98%')
.attr('src', 'http://files.cryoffalcon.com/bhgames/dressup/Celebrities/Wizard%20Fashion.html')
.appendTo('#popup_name');
});
});
因此,问题实际上是:我如何使用javascript加载flash内容,对吗?@t好吧,flash内容加载了,它没有问题,我所做的只是停止加载,让它只在我们单击播放按钮时加载。为什么不在单击播放按钮时动态添加iframe?这对我来说是个好主意,你能不能给我一个完整的答案,这样我就可以知道该怎么做,因为我在编码方面有点弱,因为我是注册会计师。(但我喜欢编程)@Dmitryy Chekalyuk感谢您的回复,但您可以看到,我现在拥有完整的代码,在上面提供的相同链接中,它不起作用。去谷歌chrome上使用它,然后加载游戏,它就会开始发出声音,即使你关闭它,它就像最小化未关闭一样。@CryOfFaclon,我明白了。关闭按钮将动态添加到div中,因此必须使用.live('click')而不是.click()。见更新的答案。我已经做了我所说的。但若你们不介意的话,你们可以在IE8中看到,点击播放按钮打开它,然后关闭,做3到4次,你们会看到有时候它会显示一个黑屏。如果你知道或者如何解决这个问题,这都是你的选择。这一次,我真的很感谢你,你是一个很棒的人。基于这个问题,你想在这个问题上帮助我吗?
#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;
}
<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>
$(document).ready(function(){
$('a.poplight[href^=#]').click(function() {
$('<iframe/>')
.attr('frameborder', 0)
.attr('allowTransparency', false)
.attr('scrolling', 'no')
.attr('width', '100%')
.attr('height', '98%')
.attr('src', 'http://files.cryoffalcon.com/bhgames/dressup/Celebrities/Wizard%20Fashion.html')
.appendTo('#popup_name');
});
});
$('#popup_name .close').live('click', function() {
$('#popup_name iframe').remove();
});