1、return返回值html
1)函数+括号函数
2)全部函数默认返回值:未定义spa
3)return后任何代码都不执行htm
2、定时器blog
1.setIntervalget
1)是一个实现定时调用的函数io
2)setInterval(函数,毫秒) 重复执行function
3)clearInerval( ) 清除class
2.setTimeoutcli
1)只执行一次
2)clearTimeout()清除
3、函数封装
oBtn1.onclick = function () { doMove ( oDiv, -12, 10 ); }; oBtn2.onclick = function () { doMove ( oDiv, 12, 800 ); }; function doMove ( obj, dir, target ) { clearInterval( obj.timer ); obj.timer = setInterval(function () { var speed = parseInt(getStyle( obj, 'left' )) + dir; // 步长 if ( speed > target && dir > 0 ) { // 往前跑 speed = target; } if ( speed < target && dir < 0 ) { // 日后跑 speed = target; } obj.style.left = speed + 'px'; if ( speed == target ) { clearInterval( obj.timer ); } }, 30); }