Div Scroll box for results - can it start at the bottom?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Div Scroll box for results - can it start at the bottom?

Post by simonmlewis »

Hi

I have a DIV overflow:auto scrolling box that products results of user comments from a database.

Problem is, this list is now getting very long in places, so I need to put the scroller in (simple), but here's the problem and the reason I am here........

It needs to start the scroller at the bottom!

We don't want people to have to scroll down. Yes I can put it in reverse order so they see the latest at the top, but the design for over a year now has been such that the last comment is at the bottom and then they can add theirs.

Is it technically possible to begin the scroll from the bottom of the scroll box? I haven't the first clue how to even think of how to do this. Or frankly, what to look for on Google as an answer.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Div Scroll box for results - can it start at the bottom?

Post by Eran »

You can do it using named anchors. Put a named anchor where you want the scroll to start and link to the page with a hash leading to that anchor.

Something like:

Code: Select all

<a name="start"></a>
And the link should end with #start
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Div Scroll box for results - can it start at the bottom?

Post by simonmlewis »

Yes I had thought of that, but that means the page will have to link straight to it and when they reach the product page, it will shoot straight to the bottom of the page.

Plus, no one uses a button to go to the user comments now.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Div Scroll box for results - can it start at the bottom?

Post by simonmlewis »

[text]
<a name="bottom"></a>

<script type="text/javascript">
onload = function()
{
location.href = "#bottom";
}
</script>
[/text]

I have also tried this. And yes, it works. It takes the scroller to the bottom but ALSO takes the user straight to the bottom of the page.

The page must load normally and remain at the top - but the scroller near the bottom of a fairly long page must have already scrolled straight to the bottom.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Div Scroll box for results - can it start at the bottom?

Post by Eran »

Using javascript, you can change the scroll position of an element. Something like -

Code: Select all

var comments = document.getElementById('comments'); 
comments.scrollTop = comments.scrollHeight;
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Div Scroll box for results - can it start at the bottom?

Post by simonmlewis »

Hi
You may be a "master" according to your username details, but I have no clue with Javascript or how to insert it and "make it happen".

If you could show me how to interpret that into a standard DIV, I'd be grateful.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Div Scroll box for results - can it start at the bottom?

Post by Eran »

You just used Javascript in your previous post.. if you're not familiar with Javascript, I recommend the MDC guide - https://developer.mozilla.org/en/JavaScript/Guide
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Div Scroll box for results - can it start at the bottom?

Post by simonmlewis »

That Javascript was from something I found - I did not write it. I am not a JS creator.
I really don't know anything about JS. But this result is needed as a priority, hence asking how to interpret that into JS and make it 'run'.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply