Results 1 to 3 of 3

Thread: How to set initial y value on div scroll?

  1. #1
    Join Date
    May 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to set initial y value on div scroll?

    I've added custom scrollbars to frames on my site using youngpup's modified DOM script:
    http://www.youngpup.net/_projectDire...ex4/index.html

    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:
    http://www.dynamicdrive.com/forums/s...ad.php?t=10155
    Last edited by Mistrel; 06-05-2006 at 08:40 PM.

  2. #2
    Join Date
    May 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I still need help with this one.

    Thanks.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Playing around, I really didn't figure out how the script worked but, this:

    Code:
    javascript:alert(theThumb.onDrag(0,200),theThumb.style.top='72px')
    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):

    Code:
    <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");
    
    		theScroll.load();
    
    		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));
    		}
    theThumb.onDrag(0,200);
    theThumb.style.top='72px';
    	}
    </script>
    The 200 controls how far you want the content (text) to scroll and the 72 controls the position desired for the little slider thingy.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •