AntoineW/luge

Anchor problem

Closed this issue · 11 comments

Hi,
Thanks for this very cool tool!
I use Smooth scroll but i have problem with anchor, i saw your help for # links here : https://luge.cool/docs/use-hash-links-with-transitions/ but i have error :
"error Parsing error: Unexpected token {"
i not use JS framework.

any tips ?

thx :)

Hi,
Could you share the code you wrote to do that?

This is your code :
luge.lifecycle.add('pageIn', this.navigateToTarget.bind(this))

navigateToTarget (done) {
const hash = window.location.hash
if (hash) {
const target = document.querySelector(hash)
if (target) {
window.scrollTo(0, target.getBoundingClientRect().top)
}
}

done()
}

Ok, but where do you use that? Can you show the rest of your file?

The code above has to be used inside a class, otherwise you should write it like that:

luge.lifecycle.add('pageIn', navigateToTarget)

function navigateToTarget (done) {
  const hash = window.location.hash
  if (hash) {
    const target = document.querySelector(hash)
    if (target) {
      window.scrollTo(0, target.getBoundingClientRect().top)
    }
  }

  done()
}

This is why i have a error, it is paste in my js files juste like this...
What is the right writing without class ?

I wrote it in my message above 🤔

oh i see the difference right know sorry, i check later :)

Ok that works for anchor who link to another page but when the anchor is in the same page not yet... probably a conflit with bootstrap 5..

Could you please test this file and let me know if it makes anchor links work?
You can take the content of the ZIP and paste it in your node_modules/@waaark/luge folder.

luge-0.6.6-beta.zip

Thank you!

Yes working !

Good! The new 0.6.7-beta version containing that fix is available.

@AntoineW (j'en ai marre de te faire souffrir avec mon anglais :p) j'ai trouvé un dernier truc, c'est sur Firefox, lien externe avec anchor si tu redimensionnes la page et que tu refais la manip cela remonte la page, si tu veux, je peux te montrer sur un de mes sites en dev en mp.