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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28