缓冲动画问题
var timer; function shareTabToggle(iTarget){ var ele = document.getElementById("share"); clearInterval(timer); var speed = 0; timer = setInterval(function() { if (ele.offsetLeft > iTarget) { speed = (iTarget - ele.offsetLeft)/20; } else if (ele.offsetLeft < iTarget) { speed = (iTarget - ele.offsetLeft)/20; } else { clearInterval(timer); return; } speed = speed < 0 ? Math.floor(speed) : Math.ceil(speed); ele.style.left = ele.offsetLeft + speed +"px"; },30); }; window.onload = init; function init(){ var shareTab = document.getElementById("share"); if(shareTab.addEventListener){ shareTab.addEventListener('mouseover',function(event){ event.stopPropagation();shareTabToggle(0);},false); shareTab.addEventListener('mouseout',function(){shareTabToggle(-200);},false); }else if(shareTab.attachEvent){ shareTab.attachEvent('onmouseover',function(event){ event.cancelBubble=true;shareTabToggle(0);}); shareTab.attachEvent('onmouseout',function(){shareTabToggle(-200);}); }else{ shareTab.onmouseover = function(event){ event.stopPropagation(); shareTabToggle(0); }; shareTab.onmouseout = function(){ shareTabToggle(-200); }; } }
老师举得例子是从快到慢的, 请问如果是从慢到快 应该怎么做? 数学公式是什么?