javascript - 在调整浏览器窗口大小时防止 jQuery 弹出窗口换行

标签 javascript jquery html css

我有一个 jQuery 弹出窗口,它会在您单击链接时出现。弹出窗口可以正常打开和关闭,但我希望在调整浏览器窗口大小时防止换行时弹出窗口的位置保持固定。

我通常使用少量 jQuery 代码来防止浏览器窗口调整大小,但在这个特定实例中它无法正常工作。

防止换行的 jQuery 代码:

<script src="http://wcetdesigns.com/assets/javascript/jquery.js"></script>

<script>

$(document).ready(function() {

$("[class~='floatNoWrap']").each(function () {
$(this).css("width", $(this).outerWidth());
});

});

</script>

弹出窗口的 jQuery 代码:

$(document).ready(function () { 



//open popup
$("#pop").click(function(){
$("#overlay_form").fadeIn(1000);
positionPopup();
});

//close popup
$("#close").click(function(){
$("#overlay_form").fadeOut(500);
});

//open popup 2
$("#pop2").click(function(){
$("#overlay_form2").fadeIn(1000);
positionPopup();
});

//close popup 2
$("#close2").click(function(){
  $("#overlay_form2").fadeOut(500);
});


//position the popup at the center of the page
function positionPopup(){
if(!$("#overlay_form, #overlay_form2").is(':visible')){
return;
}
$("#overlay_form, #overlay_form2").css({
left: ($(window).width() - $('#overlay_form, #overlay_form2').width()) / 2,
top: ($(window).width() - $('#overlay_form, #overlay_form2').width()) / 3,
position:'absolute'
});
}

//maintain the popup at center of the page when browser resized
$(window).bind('resize',positionPopup);



});

弹出窗口的 CSS:

#overlay_form, #overlay_form2{
font-weight:bold;
border: 2px solid;
margin: 10px 70px;
padding:35px 35px 228px 70px;
background-repeat: no-repeat;
background-position: 10px center;
width:600px;
color: #4F8A10;
background-color:#EDFCED;
position:absolute;
}

#pop, #pop2{
display: block;
border: 1px solid gray;
width: 65px;
text-align: center;
padding: 6px;
border-radius: 5px;
text-decoration: none;
margin: 0 auto;
} 

最佳答案

下面是纠正 float 弹出窗口的代码:

jQuery:

//position the popup at the center of the page
function positionPopup(){
if(!$("#overlay_form, #overlay_form2").is(':visible')){
return;
}
$("#overlay_form, #overlay_form2").css(("width", $(this).outerWidth())
);
}

关于javascript - 在调整浏览器窗口大小时防止 jQuery 弹出窗口换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22180040/

相关文章:

jquery - symfony2使用ajax模拟多个提交按钮

javascript - 使用 JavaScript 显示名字和姓氏

javascript - 使用 Java Script 或 jQuery 对特定项目进行计数并创建 HashMap

javascript - 如何控制复制到剪贴板的文本

无法从 onchange 识别 JavaScript 函数

javascript - 隐藏元素 onFocus 并显示 onBlur

javascript - 当 div 被填充/可见时触发事件

javascript - 幻灯片 - 返回第一张图片

php - Mysql搜索查询按品牌排序并求和品牌值(value)

javascript - 通过计时器在照片库上切换聚焦图片