Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > controlling an overflow scroll bar

Reply
Thread Tools

controlling an overflow scroll bar

 
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      03-11-2006
Hi,

Is it possible to use JavaScript to control how far down an overflowing
div is scrolled? The situation might be like the following.

<div style="overflow:scroll; height:3em;">
<p>One</p>
<p>Two</p>
<p>Three</p>
<p>Four</p>
<p>Five</p>
<p>Six</p>
</div>

Thanks,
Peter

 
Reply With Quote
 
 
 
 
TheBagbournes
Guest
Posts: n/a
 
      03-11-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> Is it possible to use JavaScript to control how far down an overflowing
> div is scrolled? The situation might be like the following.
>
> <div style="overflow:scroll; height:3em;">
> <p>One</p>
> <p>Two</p>
> <p>Three</p>
> <p>Four</p>
> <p>Five</p>
> <p>Six</p>
> </div>
>
> Thanks,
> Peter
>


You can set the scrollTop property of the div. You'll need to identify
the div with an id, so that you can access it.
 
Reply With Quote
 
 
 
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      03-11-2006
> You can set the scrollTop property of the div.

This works in all browsers? My 2002 book implies only in IE.

Thanks,
Peter

 
Reply With Quote
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      03-11-2006
It seems to be working in Safari and Firefox.

The math seems strange. I can't seem to do things like

document.findElementById("of").scrollTop = "50%"
document.findElementById("of").scrollTop =
document.findElementById("of").scrollHeight/2

Any way to control by percentage?

Thanks,
Peter

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      03-11-2006
(E-Mail Removed) said the following on 3/11/2006 12:42 PM:
> It seems to be working in Safari and Firefox.
>
> The math seems strange. I can't seem to do things like
>
> document.findElementById("of").scrollTop = "50%"
> document.findElementById("of").scrollTop =
> document.findElementById("of").scrollHeight/2
>
> Any way to control by percentage?


Try turning error reporting on and use getElementById or do you have
findElementById defined somewhere?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      03-11-2006
oops, sorry, I meant getElementById. Switching from Rails to JavaScript
can cause me some grief. Anyway I tried the example with
getElementById. I can do this

e = document.getElementById("of");
e.scrollTop = e.scrollHeight;

but actually that is way overkill. The scrollHeight is a number much
larger than necessary to scroll all the way to the bottom.

Any ideas about percentage control or something like it?

Thanks,
Peter

 
Reply With Quote
 
TheBagbournes
Guest
Posts: n/a
 
      03-11-2006
(E-Mail Removed) wrote:
> oops, sorry, I meant getElementById. Switching from Rails to JavaScript
> can cause me some grief. Anyway I tried the example with
> getElementById. I can do this
>
> e = document.getElementById("of");
> e.scrollTop = e.scrollHeight;
>
> but actually that is way overkill. The scrollHeight is a number much
> larger than necessary to scroll all the way to the bottom.
>
> Any ideas about percentage control or something like it?


It's a pixel value, nothing like the CSS style values that take %ages.
You'll have to do the %age calculations yourself using scrollTop,
scrollHeight and clientHeight.
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-12-2006
(E-Mail Removed) wrote:

> Is it possible to use JavaScript to control how far down an overflowing
> div is scrolled? The situation might be like the following.


Yes. But if there was no client-side script support it would not work, so
you should try a different approach first. One may be to tell what your
problem is in the first place instead of asking how something can be done
that you think is the solution to the problem.


PointedEars
 
Reply With Quote
 
petermichaux@yahoo.com
Guest
Posts: n/a
 
      03-12-2006
It's for drag and drop. I'm want to make a dragged item automatically
scroll down an overflowing div.

Are there situations where JavaScript is available but when the
suggested solutions would not be supported?

Peter

 
Reply With Quote
 
TheBagbournes
Guest
Posts: n/a
 
      03-12-2006
(E-Mail Removed) wrote:
> It's for drag and drop. I'm want to make a dragged item automatically
> scroll down an overflowing div.
>
> Are there situations where JavaScript is available but when the
> suggested solutions would not be supported?


You should use the Yahoo UI to do that. It handles auto scrolling during
a drag operation.

http://developer.yahoo.net/yui/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
disable title bar, status bar, and address bar of a window Matt HTML 9 08-23-2004 07:49 PM
javascript to disable the title bar, status bar, and address bar of a window Matt Javascript 9 08-23-2004 01:23 PM
Re: disable title bar, status bar, and address bar of a browser window John Hann ASP .Net 0 08-21-2004 05:07 AM
disable title bar, status bar, and address bar of a browser window Matt ASP .Net 0 08-21-2004 03:50 AM
Open in Title-Bar-Scroll-Bar-Only Window? George ASP .Net 4 02-13-2004 09:29 AM



Advertisments