2010-06-05 76 views
0

我有一个数组设置每个隐藏div的高度,但是当我使用它时,div会立即跳下来,而不是像文字数字那样缓慢滑动。Mootools Javascript无法推送到阵列


编辑:测试似乎表明它与推送方法的问题,因为content_height.push(item.getElement('.moreInfo').offsetHeight);alert(content_height[i]);给出定义,但alert(item.getElement('.moreInfo').offsetHeight);给出了正确的价值观


的Javascript:

window.addEvent('domready', function(){ 

var content_height = [];i=0; 

$$('.bio_accordion').each(function(item){ 
    i++; 
    content_height.push(item.getElement('.moreInfo').offsetHeight); 
    var thisSlider = new Fx.Slide(item.getElement('.moreInfo'), { mode: 'horizontal' }); 
    thisSlider.hide(); 


    item.getElement('.moreInfo').set('tween').tween('height', '0px'); 

    var morph = new Fx.Morph(item.getElement('.divToggle')); 
    var selected = 0; 
    item.getElement('.divToggle').addEvents({ 
    'mouseenter': function(){ 
    if(!selected) this.morph('.div_highlight'); 
    }, 

    'mouseleave': function(){ 
    if(!selected) { 
    this.morph('.divToggle'); 
    } 
    }, 

    'click': function(){ 
    if (!selected){ 
    if (this.getElement('.symbol').innerHTML == '+') 
    this.getElement('.symbol').innerHTML = '-'; 
    else 
    this.getElement('.symbol').innerHTML = '+'; 
    item.getElement('.moreInfo').set('tween', { 
    duration: 1500, 
    transition: Fx.Transitions.Bounce.easeOut 
    }).tween('height', content_height[i]); //replacing this with '650' keeps it smooth 
    selected = 1; 
    thisSlider.slideIn(); 
    } 
    else{ 
    if (this.getElement('.symbol').innerHTML == '+') 
    this.getElement('.symbol').innerHTML = '-'; 
    else 
    this.getElement('.symbol').innerHTML = '+'; 
    thisSlider.slideOut(); 
    item.getElement('.moreInfo').set('tween', { 
    duration: 1000, 
    transition: Fx.Transitions.Bounce.easeOut 
    }).tween('height', '0px'); 
    selected = 0; 
    } 
    } 
    }); 

}); 




}); 

这是为什么呢?非常感谢!

+0

你检查,看看是否“的offsetHeight”正在恢复你附有“px”的值?你确定它不是像“汽车”?它可能是一个字符串,而不是一个数字? – Pointy 2010-06-05 03:13:38

+1

仅供参考:您不需要手动增加'i',只需使用'els.each(fn(el,index){});'。 – 2010-06-05 06:32:47

回答

0

您需要content_height [i - 1]。

而且我会建议更换使用另一个索引(使用全局变量“我”,因为你的代码,这可能是因为封锁的失败):

$$('.bio_accordion').each(function(item, index) { 
    content_height[index] = item.getElement('.moreInfo').offsetHeight; 

    .... 

    tween('height', content_height[index]); 


});