我有一种情况,我们使用jQuery-UI对话框来确认页面提交,但是在禁用javascript时退回到html div。问题在于,在启用javascript的模式下,html div会短暂闪烁(“闪烁”)。
这是jQuery版本的样子:
这是html版本的样子:
由于jquery版本在更改页面之前被捕获,因此它与提交之前的“提交”按钮显示在同一页面上; html版本必须在提交后出现,因此它出现在下一页。
如上所述,jquery版本具有html版本的快速闪烁。
html的代码如下:
$display_msg = '<div id="display_msg" class="display_msg_no_js">' . $_SESSION['errmsg'] . '</div>';
请注意,两个版本均使用相同的html:通过jQuery-UI或html显示。
CSS如下:
.display_msg
{
display: none;
}
.display_msg_no_js
{
left: 15%;
width: 67%;
position: absolute;
top: 12rem;
font: bold 1.6rem 'Arial Black',sans-serif;
border: 2px solid #800;
color: #800;
max-width: 40rem;
padding: .5rem 1rem;
background-color: #fff;
border-radius: 1rem;
box-shadow: 4px 4px 12px #888;
}
jquery如下:
$('#display_msg').addClass('display_msg').removeclass('display_msg_no_js').dialog(
{
show: "fade",minHeight: 222,open: function(event,ui)
{
$(".ui-dialog-titlebar-close").hide(); // Remove the closing 'X' from the dialog
},title: $('#display_msg').attr("title") || 'Notice',modal: true,resizable: false,width: 300,maxWidth: 300,fluid: true,buttons:
{
Ok: function()
{
$(this).dialog('close');
}
}
});
在寻找消除眨眼的方法时,我遇到了How to hide elements with jQuery before they get rendered?上的页面,特别是Ryan Ore的答案,但是应用这些技术的变体是行不通的。到目前为止,消除闪烁的结果还阻止了html版本的显示。