function GetScrollSize () { this.X = (window.pageXOffset) ? window.pageXOffset : (document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : (document.body) ? document.body.scrollLeft : undefined; this.Y = (window.pageYOffset) ? window.pageYOffset : (document.documentElement.scrollTop) ? document.documentElement.scrollTop : (document.body) ? document.body.scrollTop : undefined; return this; } function GetPosition (target) { try { this.X = target.offsetLeft; this.Y = target.offsetTop; if (target != document.body) { var temp = target.offsetParent; while (temp != document.body) { this.X += temp.offsetLeft; this.Y += temp.offsetTop; temp = temp.offsetParent; } } this.X += document.body.offsetLeft; this.Y += document.body.offsetTop; return this; } catch (e) { return null; } } function GoScroll () { var Size = new GetScrollSize(); var Pos = new GetPosition(document.getElementById("sidebar")); // 100はウィンドウ上部からのオフセット // 3は適当な数字。大きいと動くスピードが遅くなるはず var Distance = (Size.Y -288 - Pos.Y)/3; document.getElementById("sidebar").style.top = Pos.Y + Distance + "px"; } window.onload = function () { // 100は更新間隔で単位はミリ秒 setInterval("GoScroll()", 100); }