使用CSS、Jquery缩放弹出框
我正在我的网站主页中创建弹出框。我从堆栈中的另一个线程引用了这段代码,它按照我的要求工作 下面的代码将为我提供正确的弹出框。但是我需要将弹出框设置为页面的1/4,可以吗使用CSS、Jquery缩放弹出框,jquery,html,css,Jquery,Html,Css,我正在我的网站主页中创建弹出框。我从堆栈中的另一个线程引用了这段代码,它按照我的要求工作 下面的代码将为我提供正确的弹出框。但是我需要将弹出框设置为页面的1/4,可以吗 <div id="boxes"> <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> <img src="images/coupon2011.jpg" width="507" h
<div id="boxes">
<div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window">
<img src="images/coupon2011.jpg" width="507" height="300" />
<a href="#" class="close"><img src="images/closelabel.gif" width="66" height="22" /></a>
</div>
<!-- Mask to cover the whole screen -->
<div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Check if cookie exists
if (Cookies.get('popunder')) {
return;
}
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth 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);
// Set cookie to be sure the popover activated again
Cookies.set('popunder', '1');
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
$(文档).ready(函数(){
//检查cookie是否存在
if(Cookies.get('popunder')){
返回;
}
变量id='#对话框';
//获取屏幕的高度和宽度
var maskHeight=$(document.height();
var maskWidth=$(window.width();
//设置遮罩的高度和宽度以填充整个屏幕
$('#mask').css({'width':maskWidth,'height':maskHeight});
//过渡效应
$('面具').fadeIn(1000);
$(#mask').fadeTo(“慢”,0.8);
//获取窗口的高度和宽度
var winH=$(window.height();
var winW=$(window.width();
//将弹出窗口设置为居中
$(id).css('top',winH/2-$(id).height()/2);
$(id).css('left',winW/2-$(id).width()/2);
//过渡效应
美元(id).fadeIn(2000年);
//设置cookie以确保popover再次激活
Cookies.set('popunder','1');
//如果单击“关闭”按钮
$('.window.close')。单击(函数(e){
//取消链接行为
e、 预防默认值();
$(“#掩码”).hide();
$('.window').hide();
});
//如果单击了“遮罩”
$(“#掩码”)。单击(函数(){
$(this.hide();
$('.window').hide();
});
});
提前谢谢……你能试试这个吗
$(文档).ready(函数(){
//检查cookie是否存在
if(Cookies.get('popunder')){
返回;
}
变量id='#对话框';
//获取屏幕的高度和宽度
var maskHeight=$(document).height()/2;
var maskWidth=$(窗口).width()/2;
//设置遮罩的高度和宽度以填充整个屏幕
$('#mask').css({'width':maskWidth,'height':maskHeight});
//过渡效应
$('面具').fadeIn(1000);
$(#mask').fadeTo(“慢”,0.8);
//获取窗口的高度和宽度
var winH=$(window.height();
var winW=$(window.width();
//将弹出窗口设置为居中
$(id).css('top',winH/2-$(id).height()/2);
$(id).css('left',winW/2-$(id).width()/2);
//过渡效应
美元(id).fadeIn(2000年);
//设置cookie以确保popover再次激活
Cookies.set('popunder','1');
//如果单击“关闭”按钮
$('.window.close')。单击(函数(e){
//取消链接行为
e、 预防默认值();
$(“#掩码”).hide();
$('.window').hide();
});
//如果单击了“遮罩”
$(“#掩码”)。单击(函数(){
$(this.hide();
$('.window').hide();
});
});
要将某个内容设置为视口的1/4,这几乎就是页面,您需要在弹出窗口上设置属性宽度:25vw
,然后使用一些技术将模式居中。如果这就是你的意思
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Check if cookie exists
if (Cookies.get('popunder')) {
return;
}
var id = '#dialog';
//Get the screen height and width
var maskHeight = $(document).height()/2;
var maskWidth = $(window).width()/2;
//Set heigth 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);
// Set cookie to be sure the popover activated again
Cookies.set('popunder', '1');
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>