function jumpobj(elem, range, startfunc, endfunc) { var curmax = range = range || 6; startfunc = startfunc || function(){}; endfunc = endfunc || function(){}; var drct = 0; var step = 1; init(); function init() { elem.style.position = 'relative';active() } function active() { elem.onmouseover = function(e) {if(!drct)jump()} } function deactive() { elem.onmouseover = null } function jump() { var t = parseint(elem.style.top); if (!drct) motionstart(); else { var nexttop = t - step * drct; if (nexttop >= -curmax && nexttop <= 0) elem.style.top = nexttop + 'px'; else if(nexttop < -curmax) drct = -1; else { var nextmax = curmax / 2; if (nextmax < 1) {motionover();return;} curmax = nextmax; drct = 1; } } settimeout(function(){jump()}, 200 / (curmax+3) + drct * 3); } function motionstart() { startfunc.apply(this); elem.style.top='0'; drct = 1; } function motionover() { endfunc.apply(this); curmax = range; drct = 0; elem.style.top = '0'; } this.jump = jump; this.active = active; this.deactive = deactive; }