OK, as I was testing this on the parent frame, I got one of the many references to window mixed up. I think this fixes that. I still have some question about how I arrive at the distance to scroll, but I will figure that out later. This version should at least be in the neighborhood:
Code:
<script type="text/javascript">
if(window.addEventListener && typeof window.scrollY === 'number'){
var scrollTrac = {};
document.addEventListener('mousedown', function(e){
if(e.target.hash){
scrollTrac.el = e.target;
scrollTrac.Y = parent.scrollY;
}
}, false);
document.addEventListener('click', function(e){
if(e.target === scrollTrac.el){
setTimeout(function(){
if(scrollTrac.Y !== parent.scrollY){return;}
if(scrollTrac.el.hash === '#top'){parent.scrollTo(0, 497); return;}
var gotoel = document.getElementsByName(scrollTrac.el.hash.substring(1))[0];
parent.scrollTo(0, gotoel.offsetTop + parent.innerHeight - gotoel.parentNode.offsetHeight);
}, 300);
}
}, false);
}
</script>
If that works, even if it doesn't, try:
Code:
<script type="text/javascript">
if(window.addEventListener && typeof window.scrollY === 'number'){
var scrollTrac = {};
document.addEventListener('mousedown', function(e){
if(e.target.hash){
scrollTrac.el = e.target;
scrollTrac.Y = parent.scrollY;
}
}, false);
document.addEventListener('click', function(e){
if(e.target === scrollTrac.el && scrollTrac.el.scrollIntoView){
setTimeout(function(){
if(scrollTrac.Y !== parent.scrollY){return;}
document.getElementsByName(scrollTrac.el.hash.substring(1))[0].scrollIntoView();
}, 300);
}
}, false);
}
</script>
This one is much better - if it works, if it doesn't, I see a way to tweak it.
Bookmarks