ddrjm ddrjm - 5 months ago 12
jQuery Question

Force scroll on a specific url

I am trying to achieve an effect/redirect on a website I'm developing for my company.

Previously we have had a

mydomain.com/weather
, direct to a specific page showing the weather. Now, since we moved the weather to a section of the root page (
/
), we want the users who go to
mydomain.com/weather
to land on the root page but with the window scrolled to the weather section.

Essentially, i'm trying to achieve the same effect of a same page anchor (
#myAnchor
) but with a url.

I've searched on Google for same page anchor url slash but I only could find stuff regarding the regular anchors.

Any help would be appreciated.

Answer

I managed to get the desired result using a combination of the answer above and window.pathname essentially:

$(window).load(function() {
    if(window.pathname == '/weather') {
      $('html, body').animate({
          scrollTop: $('#weather-area').offset().top
      }, 3000);
    }
});