首页 新闻 会员 周边

javascript动画问题

0
[已解决问题] 解决于 2009-06-27 23:21

初学面向对象javascript,写程序如下(目的是使一个Div高度慢慢缩短,最后消失):

var animateObj = function() {
    this.animateTimer = "";
    this.intervalTime = 1;
    this.divEl = null;
    this.divHeight = 0;
    this.shortElRegularly = function() {
        if (divHeight > 0) {
            divEl.style.height = divHeight.toString() + "px";
            divHeight--;
        }
        else {
            clearInterval(animateTimer);
            hide(divEl);
            divEl.style.removeAttribute("height");
        }
    }
    this.startShortAnimate = function(el) {
        divEl = el;
        divHeight = divEl.scrollHeight;
        alert('1');
        animateTimer = setInterval(this.shortElRegularly, intervalTime);
        alert('2');
    }
}
function cutDisplay(el) {
    if (!isHide(el)) {
        var animateObjInstance = new animateObj();
        animateObjInstance.startShortAnimate(el);
    }
}

调用后只能执行到alert('1');执行不知alert('2');

请问setInterval应该怎么写啊?还有哪些地方写的不合适的?请大家赐教。。。

问题补充: 哇赛,问题里不能有alert啊,alert被过滤掉了啊,提醒一下,上面只有分号的两行,第一行是a l e r t (1);第二行是a l e r t(2); 只能执行到1,不能执行到2
灰灰狼的主页 灰灰狼 | 初学一级 | 园豆:5
提问于:2009-06-27 07:34
< >
分享
最佳答案
0

animateTimer = setInterval(this.shortElRegularly, intervalTime);
改成这样试试:
animateTimer = setInterval(function(self){return function(){self.shortElRegularly();}}(this), intervalTime);

不好意思,写漏了一个括号.

I,Robot | 大侠五级 |园豆:9783 | 2009-06-27 09:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册