View Full Version : How to set initial y value on div scroll?

06-05-2006, 01:43 PM
I've added custom scrollbars to frames on my site using youngpup's modified DOM script:

I would like to use a function maxY() "onLoad" to set the scrollbar's initial y value to its maximum on divs I want to start at the bottom and scroll backwards.

I'm not familiar enough with javascript to manage this one. I know it's simple but I can't make sense of how to make it work from this code.

Any help would be appreciated.

I have another post about the same control here:

06-14-2006, 01:03 AM
I still need help with this one.


06-14-2006, 05:32 AM
Playing around, I really didn't figure out how the script worked but, this:


Pasted into the address bar made the example scroller you linked to in your post go to the bottom. So, I'd try adding it to the onload function (from your demo link):

<script language="javascript">
var theHandle, theRoot, theThumb, theScroll;
var thumbTravel, ratio;

theScroll = new ypSimpleScroll("scroll", 2, 19, 128, 75);

window.onload = function() {
theHandle = document.getElementById("handle");
theRoot = document.getElementById("root");
theThumb = document.getElementById("thumb");


Drag.init(theHandle, theRoot);
Drag.init(theThumb, null, 135, 135, 19, 71);

// the number of pixels the thumb can travel vertically (max - min)
thumbTravel = theThumb.maxY - theThumb.minY;

// the ratio between scroller movement and thumbMovement
ratio = theScroll.scrollH / thumbTravel;

theThumb.onDrag = function(x, y) {
theScroll.jumpTo(null, Math.round((y - theThumb.minY) * ratio));

The 200 controls how far you want the content (text) to scroll and the 72 controls the position desired for the little slider thingy.