私はJQueryをまったく使わずに同じことをすることができました...
function hMove(element, endPos, duration) {
// element = DOM element to move
// endPos = element.style.left value for the element in its final position
// duration = time in ms for the animation
// var leftPos = element.style.left.replace(/px/,""); // Get the current position of the element
var leftPos = window.getComputedStyle(element,null).getPropertyValue("left").replace(/px/,"");
var animStep = (leftPos - endPos) / (duration / 10); // Calculate the animation step size
var direction = ( leftPos > endPos ) ? "left" : "right"; // Are we moving left or right?
function doAnim() { // Main animation function
leftPos = leftPos - animStep; // Decrement/increment the left position value
element.style.left = leftPos + "px"; // Apply the new left position value to the element
// Are we done yet?
if ((direction == "left" && leftPos <= endPos) || (direction == "right" && leftPos >= endPos)) {
clearInterval(animLoop); // Stop the looping
element.style.left = endPos + "px"; // Correct for any fractional differences
}
} // and of main animation function
var animLoop = setInterval(doAnim, 10); // repeat the doAnim function every 10ms to animate
}
このソリューションの完全な動作デモ (非表示/表示のトグル機能を追加) は次のとおりです: http://jsfiddle.net/47MNX/16/
そのままの JavaScript を使用しており、非常に柔軟で適応性が高いはずです。
-FM