Tuesday, 15 March 2011

html5 - Creating an anchor point on a div with an offset in JQuery -


I'm trying to get my link to go to an anchor point on the other webpage, in this case a device A unique ID However, as there is a menu with a CSS positioning set (at the top of the divis), I have to offset my position where this is the 'top' effect I have tried the following code, but there is no luck Also welcome help

  & lt; A href = "contact-us.html # book" class = "book" & gt; Book A Place & lt; / A & gt;  
  $ ('a ^ [^ ^' 'book'] '). ('Click, function (e) {e.preventDefault (); var target = this.hash; var $ target = $ (target); $ (' html, body '), stop (). Animate ({' scrollTop ': $ Target.offset (). Top}, 900,' swing ', function () {window.location.hash = target;})}}  

$ ('a [original ^ ". Book"]') a a element Attempts to select the href attribute starts with ".book". Your a element's href "contact-us" Starts with and does not contain ".book" in the .book though a class choice by itself Nakara, and attempts to select the element whose class attribute is equal to "book", therefore, I think what you want to do:

  $ ('A.book'). ('Click', function (e) {...})  

After changing it, your In a element, there is no hash property from the href element of #book to get value Keeping this in mind that you will need to remove it separately If you want to be already at work /contact-us.html, you can change your code to href instead of just in #book :

  & lt; A href = "# book" category = "book" & gt; ... & lt; / A & gt;  

Then drag the entire href :

  var target = this.href;  

No comments:

Post a Comment