我差不多完成了..但是出了点问题:
function doAlert(title,text) {
var alrt='<div onclick="this.parentNode.removeChild(this);" id="alert" style="background-attachment: scroll !important;background-clip: border-box !important;background-color: black !important;background-image: none !important;background-origin: padding-box !important;background: black !important;border-bottom-left-radius: 20px 20px !important;border-bottom-right-radius: 20px 20px !important;border-top-left-radius: 20px 20px !important;border-top-right-radius: 20px 20px !important;color: white !important;display: block !important;height: 480 !important;left: 50% !important;margin-bottom: 0 !important;margin-left: -360px !important;margin-right: 0 !important;margin-top: -260 !important;opacity: 0.8 !important;overflow-x: auto !important;overflow-y: auto !important;overflow: auto !important;padding-bottom: 20px !important;padding-left: 20px !important;padding-right: 20px !important;padding-top: 20px !important;position: absolute !important;text-align: center !important;top: 50% !important;width: 640 !important;z-index: 99999999 !important;font-size:3em !important;">';
alrt+=title;
alrt+='<div id=alertbody style="text-align: justify;font-size:.5em;">';
alrt+=text;
alrt+='</div>';
alrt+='</div>';
var zalert=document.createElement("div");
zalert.innerHTML=alrt;
document.body.insertBefore(zalert.firstChild,document.body.firstElementChild)
}
此功能在普通页面上效果很好。
它不在样式繁重的页面上。
我试图在样式中添加“!important”,但这没有帮助。
如果您在诸如http://www.zibri.org之类的页面中尝试此代码,例如,请求者的大小不正确,位置也不正确。
有什么问题?
最佳答案
问题是某些宽度和高度缺少“ px”。
干得好:
function doAlert(title,text) {
var alrt='<div onclick="this.parentNode.removeChild(this);" id="alert" style="background-attachment: scroll !important;background-clip: border-box !important;background-color: black !important;background-image: none !important;background-origin: padding-box !important;background: black !important;border-bottom-left-radius: 20px 20px !important;border-bottom-right-radius: 20px 20px !important;border-top-left-radius: 20px 20px !important;border-top-right-radius: 20px 20px !important;color: white !important;display: block !important;height: 480px !important;left: 50% !important;margin-bottom: 0 !important;margin-left: -360px !important;margin-right: 0 !important;margin-top: -260px !important;opacity: 0.8 !important;overflow-x: auto !important;overflow-y: auto !important;overflow: auto !important;padding-bottom: 20px !important;padding-left: 20px !important;padding-right: 20px !important;padding-top: 20px !important;position: fixed !important;text-align: center !important;top: 50% !important;width: 640px !important;z-index: 99999999 !important;font-size:3em !important;">';
alrt+=title;
alrt+='<div id=alertbody style="text-align: justify;font-size:.5em;">';
alrt+=text;
alrt+='</div>';
alrt+='</div>';
var zalert=document.createElement("div");
zalert.innerHTML=alrt;
document.body.insertBefore(zalert.firstChild,document.body.firstElementChild)
}
随时进行改进..但将结果发布在这里! :)
关于javascript - javascript透明警报居中并位于顶部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2001509/