Closed Thread Icon

Topic awaiting preservation: Way of using Javascript to scroll a div to anchor tag (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26009" title="Pages that link to Topic awaiting preservation: Way of using Javascript to scroll a div to anchor tag (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Way of using Javascript to scroll a div to anchor tag <span class="small">(Page 1 of 1)</span>\

 
Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole in the Ozone
Insane since: Mar 2002

posted posted 06-10-2005 18:46

Is there any way to use a Javascript function to move a div to a specified anchor tag?
(needs to work in firefox and IE)

Thanks,



- Biggie

- Face the Present
- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 06-10-2005 19:00

yep, of course there is.
You have to retrieve the position of the anchor tag first. To do so, you'll most certainly have to get the handle of the anchor tag, then go through its parent nodes to iterate their offsetLeft and offsetTop positions to get the real position of the anchor.

IIRC Peter-Paul Koch has done such a function ( to retrieve the x and y of any element ), and it's certainly been posted here too.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-10-2005 19:35

Just because I have this sitting here I'll drop them:

code:
function findPosX(obj) {
    var curtop = 0;
	  if (obj.offsetParent) {
		    while (obj.offsetParent) {
			       curtop += obj.offsetLeft
			       obj = obj.offsetParent;
		    }
    }
	  else if (obj.x) curtop += obj.x;
	  return curtop;
}

function findPosY(obj) {
    var curtop = 0;
	  if (obj.offsetParent) {
		    while (obj.offsetParent) {
			       curtop += obj.offsetTop
			       obj = obj.offsetParent;
		    }
    }
	  else if (obj.y) curtop += obj.y;
	  return curtop;
}



Are you talking about moving a div like a tooltip? (of which there are plenty of examples) or scrolling an overflow div to a specific link within the div?



.:[ Never resist a perfect moment ]:.

Maskkkk
Paranoid (IV) Inmate

From: Willaimsport, PA, US of A the hole in the Ozone
Insane since: Mar 2002

posted posted 06-10-2005 23:39

I mean an overflow div.



- Biggie

- Face the Present
- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011


(Edited by Maskkkk on 06-10-2005 23:40)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 06-11-2005 00:11

Well that's much easier it's just like going to any link.

Name the Link something

<a href="test">test</a>


then

document.location = '#test'

If you are doing this from a link it's even easier and you don't even need js just

<a href="#test">go to test</a>



.:[ Never resist a perfect moment ]:.

(Edited by bitdamaged on 06-11-2005 00:12)

« BackwardsOnwards »

Show Forum Drop Down Menu