首页 新闻 会员 周边

请javascript高手来一下下,setInterval怎么写。。。

0
[已关闭问题]

function animateObj() {
    var animateTimer = null;
    var intervalTime = 1;
    var divEl = null;
    var divHeight = 0;
    this.shortElRegularly = function() {
        aler t('2');
        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;
        aler t('1');
        animateTimer = setInterval("this.shortElRegularly()", intervalTime);
        aler t('3');
    }
}

var animateObjInstance = new animateObj();
animateObjInstance.startShortAnimate($('divId'));

 

以上代码是实现一个隐藏某Div时的一个动画效果(即每一毫秒缩短一个像素),可程序能执行到 aler t('1'); 和 aler t('3');,就是不能执行 aler t('2');,应该是setInterval的写法不对吧,应该怎么写呀。。。啊啊啊,我快郁闷死了。。。

灰灰狼的主页 灰灰狼 | 初学一级 | 园豆:5
提问于:2009-06-27 17:53
< >
分享
其他回答(1)
0

我不是在你上一个提问中回答了吗?开始写漏了个括号,下午改了,你再试试吧.

I,Robot | 园豆:9783 (大侠五级) | 2009-06-27 20:42
0

var self = this;

animateTimer = setInterval(function(){self.shortElRegularly();}, intervalTime);

microdot | 园豆:197 (初学一级) | 2009-06-29 16:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册