0

I want the url to be changed depending of the content that is focused on the site. If I am reading a article and the header is called "economics" I want to add "#economics" as an anchor tag to the url so the users easy can copy the url to share a specific article. Its kinda hard to explain so here is a site that have the scroll/url function that I am looking for: WEBSITE (try to scroll down).

What is this called and how can i get started?

pat
  • 103
  • 1
  • 14
  • did you try any thing?? – Anshuman Aug 16 '18 at 12:28
  • @iNullPointer Well i have some ideas ex: a js script that fires on scroll event that takes the closest

    tag with a specific class and adds the text to the url. But i want some more "understanding" before proceeding

    – pat Aug 16 '18 at 12:31
  • 1
    This may help you https://stackoverflow.com/questions/14660580/change-url-when-manually-scrolled-to-an-anchor – hans-könig Aug 16 '18 at 12:33

1 Answers1

0

You can trigger scroll with Waypoint and add hash string to url.

For example:

var waypoint = new Waypoint({
  element: document.getElementById('economics'),
  handler: function(direction) {
    window.location.hash = '#economics';
  }
})

When other users come from the URL, you can get hash from url and scroll to element. You can do this with jQuery scrollTop function.

I hope, i could help you.

Emircan Ok
  • 320
  • 2
  • 13