0

I want used the target css selector and anchor to manage tabs on my website, but i don't want modify my url. How can i prevent url rewriting?

It is possible to prevent scroll to element too? How?

I have tried intercept :

$('a[href^=#]').on 'click', (event)->
    event.preventDefault()

but doesn't works.

Matrix
  • 3,458
  • 6
  • 40
  • 76
  • Maybe this can help you http://stackoverflow.com/questions/5928435/append-remove-anchor-name-from-current-url-without-refresh – daker Dec 11 '13 at 18:08

1 Answers1

1

It won't work because this way, or your link reacts on click and it brings you to your anchor, or it doesn't get the click and takes you nowhere.

The trick is to use an anchor the old way (<a id="anchor"></a>) right before or right inside the element you are targeting and set anchor in position:fixed;top:0;left:0; , this way your anchor always remain on top of screen and no scrolling is needed.

The problem is that your anchor becomes inefficient if content to reach is off screen and in normal flow. I guess you have a good reason to want to avoid your page to be jumpy :)

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129