Forum Moderators: open

Message Too Old, No Replies

The text is not loading at the Top

         

charlee

11:04 pm on May 27, 2008 (gmt 0)

10+ Year Member



Hi, I created a webpage where the user can see some images at the right side and a big divission at the left with some text. Now when the user clicks on one of these images the text at left changes with javascript, because I created several variables with text inside and this way I show this info whenever I want. So far it looks like Im in the wrong forum since Im talking abour javascript but the thing is that the problem is XHTML/CSS and dont even know if probably might be javascript :(.

The divission which holds the next has an overflow: auto, so the user can scroll the text.

Now, The problem:

If a user clicks on an image it opens perfectly at the left divission but if the user scroll the text for reading and after he clicks on a second image then the the new text loads perfectly but the scroll conserves its position so you have to scroll up to see the beginning of the text.

this is the link on the image:
<a href="javascript:showScoop('4')"><img src="../images/scoop/Scoop4Thumb.jpg"/></a>

I tried adding an anchor at the top of my text and do this

<a href="javascript:showScoop('4'); #top"><img src="../images/scoop/Scoop4Thumb.jpg"/></a>

but that doesnt work, i was not expecting something different but I had to try I coudnt help it.

Can somebody tell me how can i load my text and reset the scroll position so the new text loaded starts from the top?

thanks in advance.

penders

8:36 am on May 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...load my text and reset the scroll position...

I think you are heading in the right direction... I believe you can reset the scroll position of the container in JavaScript using the elements .scrollTop method (although it's not part of the W3C spec and I'm not sure about browser compatibility but should be OK in FF and IE)?

Something like:

element.scrollTop = 0;

Mozilla - DOM:element.scrollTop [developer.mozilla.org]

charlee

3:40 pm on May 28, 2008 (gmt 0)

10+ Year Member



Hey hey thanks, I dont know whats the support for this but I tested it in IE7, FF 2.0, Safari 3.1 and Opera 9.27 and it works perfectly but not sure for previous versions, what Im most worried about is IE6, I need to check the support for this one but so far it works! thanks

penders

4:17 pm on May 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...what Im most worried about is IE6

.scrollTop is certianly supported in IE6. I think it was introduced in IE4. How it behaves on certain elements may have varied. The DOCTYPE can play a part. As I understand it,

overflow
needs to be set, which you are doing anyway.

MSDN: scrollTop Property [msdn.microsoft.com]