我有以下代码,每次用户点击它时,我都需要创建一个按钮来反转移动方向。
我需要一些帮助。
var div_width = 87;
var div_count = 15;
var reset_offset = div_width * (div_count -1);
function init() {
// Set initial position - note that the first div will
// be off the lefthand side
for(i=0;i<div_count;i++) {
var foo = document.getElementById('fooObject' + i);
foo.style.left = ''+(i*div_width)+'px';
}
doMove();
}
function doMove() {
for(i=0;i<div_count;i++) {
var foo = document.getElementById('fooObject' + i);
var left = parseInt(foo.style.left);
foo.style.left = '' + (left+1) + 'px';
if (left >= reset_offset) {
foo.style.left = '' + (-div_width) + 'px';
}
}
setTimeout(doMove, 20);
}
init();
谢谢!