2012-11-03-网页中间弹出文本框

 

核心代码是:

$(“#button”).click(function(){
var curwidth = document.body.scrollWidth;//获得当前屏幕可见部分的宽和高
var curheight = document.body.scrollHeight;//思考用了哪种高宽!
var tipswidth = $(“.tips”).width(); //获得通知栏的宽和高
var tipsheight = $(“.tips”).height();
var left = (curwidth - tipswidth) / 2 ; //计算通知栏应在的位置
var top = (curheight - tipsheight) / 2 ;
$(“.tips”).css(“left”,left);
$(“.tips”).css(“top”,top);

$(“.tips”).fadeTo(4000,1).delay(5000).fadeTo(3000,0);
});
});

 

各种宽度高度,不一一allert加上草稿纸上多加画画,还真搞不懂分不清:

网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
网页正文部分上: window.screenTop
网页正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的宽: window.screen.width
屏幕可用工作区高度: window.screen.availHeight
屏幕可用工作区宽度: window.screen.availWidth

CSS3很强大,能做出很炫的效果。

点击按钮就可以弹出像信封的提示框,见Demo.