AntoineW / luge

Luge
290 stars 10 forks source link

Anchor problem #20

Closed doreybenjamin closed 2 years ago

doreybenjamin commented 2 years ago

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 :)

AntoineW commented 2 years ago

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

doreybenjamin commented 2 years ago

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() }

AntoineW commented 2 years ago

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()
}
doreybenjamin commented 2 years ago

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

AntoineW commented 2 years ago

I wrote it in my message above 🤔

doreybenjamin commented 2 years ago

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

doreybenjamin commented 2 years ago

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..

AntoineW commented 2 years ago

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!

doreybenjamin commented 2 years ago

Yes working !

AntoineW commented 2 years ago

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

doreybenjamin commented 2 years ago

@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.