重新定义 alert

 

<div id=alertn style="position:absolute;left:40%;top:-100px;width:200px;height:100px;background-color:red;padding:10px;"></div>
<input type="button" value=" 请点两下 " onclick="alert('重新定义对话框!');run();">
<script type="text/javascript">
var onrun=false;
function run(){
if(onrun){return false;}
onrun=true;
var Ntimer=null;
	window.alert=function(Msg){
		document.getElementById("alertn").innerHTML=Msg;
		var Ntimert=0;
		clearInterval(Ntimer);
		var Ntimer=setInterval(function(){
			Ntimert++;
			if(Ntimert<31){
				document.getElementById("alertn").style.top=Math.easeOutBounce(Ntimert,-100,300,30);
			}else if(Ntimert>30){
				clearInterval(Ntimer);Ntimer=null;
			}
		},20);
	};
}
Math.easeOutBounce=function(t,b,c,d){
	switch(true){
		case(t/=30)<(1/2.75):return c*(7.5625*t*t)+b;break;
		case(t<(2/2.75)):return c*(7.5625*(t-=(1.5/2.75))*t+.75)+b;break;
		case(t<(2.5/2.75)):return c*(7.5625*(t-=(2.25/2.75))*t+.9375)+b;break;
		default:return c*(7.5625*(t-=(2.625/2.75))*t+.984375)+b;break;
	}
}
</script>

 

 

posted on 2010-06-25 09:26 陈涛 阅读(24) 评论(0) 编辑 收藏