0
我对PHP很陌生,因此定制现成的脚本并不是我的强项。PHP自定义模块显示是否存在DIV
我有一个动画的弹出式模态脚本,当点击某个特定按钮时,它会触发。我还想在页面上存在特定的div时自动触发相同的脚本。
从代码中可以看到#mask是页面上半透明的黑色层。
下面是我需要调整脚本:
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
});
});
目前,它会自动打开这个链接被点击时:
<a href="#" name="modal">
和我想要得到它的自动运行这个时页面上存在DIV:
<div name="showintrovideo"></div>
非常感谢你们,你们总是帮助很大!
- - 安德鲁
编辑
下面是完整的代码,我的工作:
HTML
<div id="boxes">
<div id="qrcodemarketing" class="window">
<!-- close button is defined as close class -->
<div style="float:right;">
<a href="#" class="close"><img src="images/close_window.png" width="22"height="22" alt="Close Window" /></a>
</div>
<iframe width="640" height="480" src="http://www.youtube.com/embed/MYVIDEO" frameborder="0" allowfullscreen></iframe><br /><b>Pause the video before closing this window</b>
</div>
</div>
<!-- Do not remove div#mask, because you'll need it to fill the whole screen -->
<div id="mask"></div>
CSS
#mask {
position:absolute;
width:100%;
height:100%;
left:0;
top:0;
z-index:9000;
background-color:#000;
display:none;
}
#boxes .window {
position:absolute;
background:none;
display:none;
z-index:9999;
padding:20px;
color:#fff;
}
个
js文件
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2);
//transition effect
$(id).fadeIn(2000);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, .window').hide();
});
//if mask is clicked
$('#mask').click(function() {
$(this).hide();
$('.window').hide();
});
});
它,它可能只是调整的.js文件,以便它也可以自动打开,以及通过点击?
谢谢!
感谢您的解决方案,马丁! 再说一遍,因为我是一个新手,你会介意看看我的整个源代码(我将其添加到问题中),看看我可以如何调整它以适用于自动打开和单击打开? 我只是不知道如何整合您的解决方案。请原谅我的缺点。 干杯! – Andrew 2012-01-12 19:09:16