下面的代码功能是,当页面加载完成后,动态添加一个DIV对象到网页里面,同时设置该层居中对齐。
var mylogodiv = window.document.createElement("div");
mylogodiv.setAttribute("id","ShowLogoPic");
mylogodiv.innerHTML="这里是动态层的内容,可自行修改";
window.document.body.appendChild(mylogodiv);
$("#ShowLogoPic").css( { "display":"none" } );
var top = ($(window).height() - $("#ShowLogoPic").height())/2;
var left = ($(window).width() - $("#ShowLogoPic").width())/2;
var scrollTop = $(document).scrollTop();
var scrollLeft = $(document).scrollLeft();
$("#ShowLogoPic").css( { "z-index":99,"position":"fixed","top": top + scrollTop,"left": left + scrollLeft } ).show();