safe scrollIntoView() for AJAX
scrollIntoView() is a very handy function, when you use elements with a scrolling overflow. if some element is not visible, because it is scrolled away, you can scroll until it is visible. there is just one little problem. it is not standard (introduced originally by Microsoft for the document.all-object) and not working in old Opera- and Safari-browsers. this is why handgestrickt wrote a safe scrollIntoView()-function, which tries several ways to do it. this function needs Prototype.js to work properly. feel free to use it.
var foo = {
scrollIntoView: function(frame,element) {
if(frame && $(frame) && element && $(element)) {
try { $(element).scrollIntoView(false); }
catch(error) {
var difference = (
(Position.positionedOffset($(element))[1]+$(element).getHeight())-
(Position.positionedOffset($(frame))[1]+$(frame).getHeight())
);
try {
if(difference > 0) $(frame).scrollTop = difference;
else $(frame).scrollTop = 0;
}
catch(error2) {
if(difference > 0) $(frame).scrollTo(0,difference);
else $(frame).scrollTo(0,0);
}
}
}
},
}

