Closed Thread Icon

Topic awaiting preservation: Moz Help.... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8487" title="Pages that link to Topic awaiting preservation: Moz Help.... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Moz Help.... <span class="small">(Page 1 of 1)</span>\

 
pwhitrow
Bipolar (III) Inmate

From: UK
Insane since: Feb 2002

posted posted 01-24-2003 13:55

trying to get the last element in a div to scroll into view. Obviously this is simple in IE, but can't get it in NN7.

trying the following code as a quick and dirty test....


<body>
<script language="JavaScript">
<!--
function go() {
if(document.all){
document.getElementById('tester').scrol*****View(true);
}else{
document.getElementById('holder').scrollTo(0,9999)
}
}

//-->
</script>

<div id="holder" style="height:200;width:500;overflow:auto;">
<pre>
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
Lots of stupid text...
</pre>
<b id="tester">test</b>
</div>

<br><br>
<b onclick="go()"> > Go < </b>

</body>


Help..?????

www.pwhitrow.com

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 01-24-2003 15:57

The scrolling code itself should work in both IE and Mozilla (I'm not sure where the five ***** came in though - was that the UBB?), but instead of checking for document.all, which is only supported by IE, you should check for document.getElementById in the if statement.

kuckus

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 01-24-2003 16:10

I was pretty sure the scrollTo function was only a method of the Window object, not of any object you wanted to use it on...

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-24-2003 16:17

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 01-24-2003 17:32

What you probably want to do, is use window.scrollTo(x,y), where x and y are the position of the element on the page.

The following functions can get the x and y positions of an element on the page:

function getLeft(theelement)
{
if (theelement.offsetParent) return theelement.offsetLeft + getLeft(theelement.offsetParent);
else return theelement.offsetLeft;
}
function getTop(theelement)
{
if (theelement.offsetParent) return theelement.offsetTop + getTop(theelement.offsetParent);
else return theelement.offsetTop;
}

Use them as follows:

var scrolltoelement = document.getElementById('tester');
window.scrollTo(getLeft(scrolltoelement),getTop(scrolltoelement));

[This message has been edited by Slime (edited 01-24-2003).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 01-25-2003 02:04

Hay, that's a really really neat way of getting top and left values of nested elements relative to the page. I'd never thought about doing it that way before.

« BackwardsOnwards »

Show Forum Drop Down Menu