By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,704 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

Question about anchors

DogBot
P: 11
To define my question I need to establish an example:
Let's say I have a web page (MYPAGE.HTML) and
this webpage is constrained in width.
This web page has 200 lines of text.
I have an anchor on line 30
Expand|Select|Wrap|Line Numbers
  1. <a name="myanchor">
and a link on the first line that points to that anchor
Expand|Select|Wrap|Line Numbers
  1. <a href="#myanchor">go to anchor</a>
If I click on the link the webpage will scroll up so that line 30
is now at the top of the browser window.

Here is the question.
I do not want line 30 to come to the top of the browser. I want it to come up to
the middle of the browser page (or any other point lower that the top of the page)
Say for example 50 pixels from the top.

I cannot do it by moving the anchor point to another line or adding another anchor point. I must do it using CSS or Javascript or both.

Don't be concerned about why, please, it will just complicate the question.My biggest problem so far has been explaining the problem!
But if you must know see this thread

Thanks
Dec 15 '09 #1
Share this Question
Share on Google+
3 Replies


RamananKalirajan
100+
P: 607
Try This

I think this is what you are looking for.

Thanks and Regards
Ramanan Kalirajan
Dec 15 '09 #2

DogBot
P: 11
Thanks Ramanan, this gives me the basic mechanism for doing this. As far as implementation I suppose I need to somehow dynamically get the current position of all anchors on the page and then programatically change them to that value + 300px(or whatever number I need)

Having said that I have no idea how one does that...but I will start searching the web for the first part (get the current position of all anchors on the page)
and go from there.

Again thanks

P.D. or maybe an "onclik" command? but this would imply inline JavaScript which i do not want to do to my client..I you have any ideas I'd appreciate them. Thanks
Dec 15 '09 #3

Dormilich
Expert Mod 5K+
P: 8,639
P.D. or maybe an "onclik" command? but this would imply inline JavaScript which i do not want to do to my client..
then use:
Expand|Select|Wrap|Line Numbers
  1. Element.onclick = fnName;
  2. // or
  3. Element.addEventListener("click", fnName, false); // true if you want to capture the event
Dec 16 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.