+ -
当前位置:首页 → 问答吧 → js 闭包错误

js 闭包错误

时间:2010-06-03

来源:互联网


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns=" http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <style type="text/css"> </style> </head> <body style="height:2000px"> <div onclick="auto.Hide('up');">向上移动</div> <div onclick="auto.Hide('down');">向下移动</div> </body> <script> var $ = function (id) { return "string" == typeof id ? document.getElementById(id) : id; } var Class={ create:function(){ return function(){ this.init.apply(this,arguments); } } } var Extend=function(destination,source){ for(var p in source){ destination[p]=source[p]; } } var MSG=Class.create(); MSG.prototype={ init:function(content,options){ document.body.style.position='relative'; this.SetOption(options); this.MSG=document.createElement('div'); for(var p in this.options){ this.MSG.style[p]=this.options[p]; } this.MSG.innerHTML=content; document.body.appendChild(this.MSG); o=this; }, SetOption:function(options){//默认 this.options={ width:'300px', height:'150px', borderWidth:'1px', borderColor:'#dddddd', borderStyle:'solid', position:'fixed', right:'2px', bottom:'2px' }; Extend(this.options,options||{}); }, Show:function(){ }, Hide:function(direction){ if(direction=='up'){ setInterval("o.MoveUp()", 10); } else{ setInterval("o.MoveDown()", 10); } }, MoveUp:function(){ if(parseInt(this.MSG.style.bottom)<0){ var y=parseInt(this.MSG.style.bottom)+1; this.MSG.style.bottom=y+'px'; } }, MoveDown:function(){ var offsetY=parseInt(this.options.height)-25; if(Math.abs(parseInt(this.MSG.style.bottom))<offsetY){ var y=parseInt(this.MSG.style.bottom)-1; this.MSG.style.bottom=y+'px'; } } } var auto=new MSG('Hello world'); </script> <html>
 提示:您可以先修改部分代码再运行
大家帮我瞧瞧,向下时可以,向上却不可,不知原因?

作者: creaivey   发布时间: 2010-06-03

问题已解决,谢谢各位。

作者: creaivey   发布时间: 2010-06-03

怎么解决的,把解决方法放出来嘛

作者: yiday   发布时间: 2010-06-03

即时清除定时器即可

作者: gukefei   发布时间: 2010-06-04