我有一個數組設置每個隱藏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;
}
}
});
});
});
這是爲什麼呢?非常感謝!
你檢查,看看是否「的offsetHeight」正在恢復你附有「px」的值?你確定它不是像「汽車」?它可能是一個字符串,而不是一個數字? – Pointy 2010-06-05 03:13:38
僅供參考:您不需要手動增加'i',只需使用'els.each(fn(el,index){});'。 – 2010-06-05 06:32:47