我正在研究一个jquery简单模态。我正在尝试加载它 - 在15秒后它会自动关闭。所以我无法实现的是,如果我为该模态设置宽度和高度,并且如果用户浏览器屏幕分辨率发生变化([ctrl(+)
]或[ctrl(-)
]),则模态的大小会有所不同。因此,我尝试使用screen.width
和screen.height
来捕获用户的屏幕分辨率,并将该宽度指定给该模态。但它搞砸了我不知道为什么。我正在尝试做的Here is the demo link。这是我正在使用的jquery代码。
<script>
$(document).ready(function() {
(function () {
var width = screen.width,
height = screen.height;
setInterval(function () {
if (screen.width !== width || screen.height !== height) {
width = screen.width;
height = screen.height;
$(window).trigger('resolutionchange');
}
}, 50);
}());
$.modal($("#basic-modal-content"));
$("#simplemodal-container").width(screen.width);
$("#simplemodal-container").height(screen.height);
});
setTimeout(function() {
$.modal.close();
}, 15000);
</script>
实际上我正试图隐藏我的屏幕并在模式中放置广告,直到页面加载。希望我的问题很明确。提前谢谢!!
答案 0 :(得分:2)
我这里有jsfiddle的更新。
我添加了这个:
modal.css({
width: w + ($(window).width() - w),
height: h + ($(window).height() - h)
});
到您的脚本。好的是modal
占据整个屏幕,另一方面,当调整窗口大小时,边框(绿色)将消失,只显示模态的内容。
但对你来说这将是一个良好的开端。
更新:
我已更新了jsfiddle here。
希望它有所帮助。
答案 1 :(得分:1)
<script>
$(document).ready(function() {
(function () {
var width = screen.width,
height = screen.height;
setInterval(function () {
if (screen.width !== width || screen.height !== height) {
width = screen.width;
height = screen.height;
$(window).trigger('resolutionchange', width, height);
}
}, 50);
}());
$.modal($("#basic-modal-content"));
$("#simplemodal-container").width(screen.width);
$("#simplemodal-container").height(screen.height);
});
$(window).on('resolutionchange', function(width, height){
$("#simplemodal-container").width(width);
$("#simplemodal-container").height(height);
//you also need to set position left:0 and top:0;
});
setTimeout(function() {
$.modal.close();
}, 15000);
</script>
但我建议使用这种方式,因为你想要填充浏览器窗口
#simplemodal-container {
left:0;
top:0;
width:100%;
height:100%;
position:fixed;
}
<script type="text/javascript">
setTimeout(function(){
$('#simplemodal-container').fadeOut();
},1500);
</script>
或以其他方式[您的解决方案]:
<script>
$(function() {
var width = screen.width,
height = screen.height;
$.modal($("#basic-modal-content"));
$("#simplemodal-container").width(width).height(height).css({top:0,left:0});
$(window).resize(function(){
width = screen.width;
height = screen.height;
$(window).trigger('resolutionchange', width, height);
});
$(window).on('resolutionchange', function(width, height){
$("#simplemodal-container").width(width).height(height).css({top:0,left:0});
//if you have padding for modal, remove it
});
setTimeout(function() {
$.modal.close();
}, 15000);
});
</script>