Avatar for Username

ძიება მხარდაჭერაში

ნუ გაებმებით თაღლითების მახეში მხარდაჭერის საიტზე. აქ არასდროს მოგთხოვენ სატელეფონო ნომერზე დარეკვას, შეტყობინების გამოგზავნას ან პირადი მონაცემების გაზიარებას. გთხოვთ, გვაცნობოთ რამე საეჭვოს შემჩნევისას „დარღვევაზე მოხსენების“ მეშვეობით.

Learn More

Internal links / anchors does not work properly after 2nd attempt (gap)

  • 1 პასუხი
  • 0 მომხმარებელი წააწყდა მსგავს სიძნელეს
  • 9 ნახვა
  • ბოლოს გამოეხმაურა negtrick

Hello,

I have a website with a summary and different chapters.

I use <a id=#SOM-XX" href="#XX"> and <a id="XX" href="#SOM-XX"> tags to allow users to go back and forth between the titles of the contents and the chapters and sub-chapters. Until recently this worked well.

Since an undetermined date, on Firefox, after a first back and forth between summary and chapters, the links from the summary do not refer exactly to the chapter concerned, but slightly higher... Smiley rolleyes The phenomenon is amplified as one chooses a chapter close to the end, for example the 5th.

Try it for yourself: https://blog.patrick-kiri.mq/2019/02/connaissances-et-orientations-patrick_15.html#lapasfc

On the other hand, everything works normally on Chrome.

How to correct this problem?

Hello, I have a website with a summary and different chapters. I use <a id=#SOM-XX" href="#XX"> and <a id="XX" href="#SOM-XX"> tags to allow users to go back and forth between the titles of the contents and the chapters and sub-chapters. Until recently this worked well. Since an undetermined date, on Firefox, after a first back and forth between summary and chapters, the links from the summary do not refer exactly to the chapter concerned, but slightly higher... Smiley rolleyes The phenomenon is amplified as one chooses a chapter close to the end, for example the 5th. Try it for yourself: https://blog.patrick-kiri.mq/2019/02/connaissances-et-orientations-patrick_15.html#lapasfc On the other hand, everything works normally on Chrome. How to correct this problem?

ყველა პასუხი (1)

For those who can be interested, I solved the problem by using this code:


(() => {

 document.querySelectorAll('a[href^="#"]').forEach((elem) => {
   elem.addEventListener('click', (e) => {
     //e.preventDefault();          
     // location.href = elem.getAttribute('href');
     
     var h = elem.getAttribute('href').replace('#', );

        
     //var top = document.getElementById(h).offsetTop; //Getting Y of target element
     //window.scrollTo(0, top); 
     document.getElementById(h).scrollIntoView(); 
   });
 });

})()

https://stackoverflow.com/questions/68467475/lazy-loading-conflicting-with-scrollto-anchor-to-id-scroll-stops-halfway-throu

https://stackoverflow.com/questions/13735912/anchor-jumping-by-using-javascript