Monday 15 August 2011

javascript - Anchoring Across Different Pages -


So now I have a script that allows anchoring, but it only works within that page, Which i currently am

  $ ('. Menu a') Click (function () {var question = this.inner html; var reply = $ .book ('dt: happens (' + question + ')'; $ ('html, body'). Animate ({scrollTop : $ (North) .offet (). Top}, 200); return back;}); & Lt; Div class = "menu" & gt; & Lt; Div & gt; & Lt; H3 class = "title" & gt; & Lt; A href = "about /" & gt; About & lt; / A & gt; & Lt; Span class = "expansion" & gt; + & Lt; / Span & gt; & Lt; / H3 & gt; & Lt; Ul class = "subheader" & gt; & Lt; Li & gt; & Lt; A href = "about /" & gt; How can you help? & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "about /" & gt; How do I submit a show? & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "about /" & gt; Who are we? & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; H3 class = "title" & gt; & Lt; An id = "contact" href = "contact" & gt; Contact & lt; / A & gt; & Lt; Span class = "expansion" & gt; + & Lt; / Span & gt; & Lt; / H3 & gt; & Lt; Ul class = "subheader" & gt; & Lt; Li & gt; & Lt; A href = "contact" & gt; Email & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "contact" & gt; On the site & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "contact" & gt; Social Media & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

I am trying to figure out how to change my current script, so that I can anchor myself in the correct position on the next page.

For example, I am currently on my page, but I click on "Email" in my menu, I have to redirect myself to the contact page for the page where the email Right now, it keeps me at the top of the page.

I'm not trying to do it with many IDs because these are not my only pages, so it would not be the best idea to have more than 30 IDs to work on this work. That this is my last resort. The question is not clear, but I think that you have a JavaScript function that takes the string and the user Finds the right place to send In that case, you can run it on the page-load with the current hash of the page:

  $ (function () {if location.hash) {var question = location.hash; Var answer = $ .find ('(' dt: happens ('+ question +'); $ ('html, body'). Animate ({scrollTop: $ (north) .offset (). Top}, 200);} });   

And your email link can look like this:

  
  • li> gt; & lt; a href = "# email Contact the "& gt; Email & lt; / a & gt; & lt; / li & gt;

    Or, if you have & lt; a & gt; < / Code> Want to use content as a hash:

      
  • A "& gt; Email & lt; / a & gt; & lt; / li & gt; ... $ (function () {$ ('a'). Each (function () {$ (this) .attr ('Url', $ (this) .attr ('url') + '#' + $ (this text ())});});




  • No comments:

    Post a Comment