SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Measuring distance from viewport edge

    Hi, I'd like to be able to place something at a specific distance from the top of the viewport upon clicking on a link regardless of how far down the user has scrolled. A bit lightbox JS, but a bit simpler.

    I could achieve this by giving the element position:fixed but since this doesn't work in IE6, it seems I'll have to use JS.

    Cheers!
    Last edited by Raffles; Sep 18, 2006 at 20:13.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I hate to bump, but I still can't find anything on google - just give me a starting point and I'll work it out. Please?

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    start here- but be aware that an element besides the body can scroll.

    Code:
    function whereAt(e){
    	var ev= window.event? event: e;
    	if(!e || e.clientX===undefined) return false;
    	var pX,pY,sX,sY;
    
    	pX= (ev.clientX);
    	pY= (ev.clientY);		
    	
    	if(window.pageXOffset){
    		sX= window.pageXOffset;
    		sY= window.pageYOffset;
    	}
    	else{
    		var d= document.documentElement;
    		var b= document.body;
    		sX= d.scrollLeft+b.scrollLeft;
    		sY= d.scrollTop+ b.scrollTop;
    	}
    	pX+=(sX)? sX: 0;
    	pY+=(sY)? sY: 0;
    
    	return [pX,pY,sX,sY];
    	
    }

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Wonderful, mrhoo, thanks so much.


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
  •