我下面的代碼我有一個UL與x3李的。我希望李的褪色在一個序列中,但我認爲在某個地方放鬆了範圍。問題是隻有序列中的最後一項運行。我最初認爲這是一個循環,所以我刪除了所有這些。任何幫助都會很棒。範圍問題與fadeIn的序列
Thanks is Advance。
function Sequence() {
var sequence = [];
var pos = 0;
Sequence.prototype.add = function(obj) {
sequence.push(obj);
};
Sequence.prototype.start = function() {
sequence[pos].run();
};
Sequence.prototype.next = function() {
pos++;
sequence[pos].run();
};
};
function fadeIn(params) {
this.id = params.id;
this.onComplete = params.onComplete;
var self = this;
var timer;
var i = params.opacity;
fadeIn.prototype.run = function(){
timer = setInterval(function() {
params.element.style.opacity = i/10;
i++;
if (i/10 == 1) {
clearInterval(timer);
self.onComplete();
}
}, params.fps);
}
};
var sequence = new Sequence();
var fader = document.getElementById('fader1');
var items = fader.getElementsByTagName("li");
sequence.add(new fadeIn({
"id": "instance_0",
"element": items[0],
"opacity": 0,
"fps": 80,
"onComplete": function() {
sequence.next();
}
}));
sequence.add(new fadeIn({
"id": "instance_1",
"element": items[1],
"opacity": 0,
"fps": 80,
"onComplete": function() {
sequence.next();
}
}));
sequence.start();
如果在每行代碼的前面添加四個空格,它應該更好地格式化它。 – 2011-04-14 21:17:38
嘿扎克,謝謝你 – iancrowther 2011-04-14 21:32:24