0

i'm creating a website which contains a smoothscroll js. Everything works fine when smoothscroll href directs to content on the same page.

But let's say that user is on webpage1 and he clicked on href which should lead and smoothscroll to "example content" on webpage2.

How to make that href link redirect the user to this page and after redirecting him, automaticlly smoothscroll to "example content".

here is an image of what i mean about that. Hope it helps in understanding my problem. https://i.postimg.cc/DzVHWsPw/image.png

I've tried using javascript load function, but without a success, perhaps i was using it the wrong way.

Here is the smoothscroll function:

(function ($) {
  "use strict";


  $('a.js-scroll-trigger[href*="#"]:not([href="#"])').click(function () {
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: (target.offset().top - 54)
        }, 1000, "easeInOutExpo");
        return false;
      }
    }
  });

})(jQuery);

Here is the HTML

<a href="#info1" class="js-scroll-trigger"><button type="button">Button</button></a>

<div id="info1">Content of info1</div>

in order it to work im using jquery.min.js and jquery.easing.js

4
  • 2
    Can you share the relevant code you wrote? Commented May 13, 2019 at 22:49
  • yeah sorry, i forgot to add it. Commented May 13, 2019 at 22:56
  • 1
    Have you looked at using window.onload and Element.scrollIntoView()? Here is a good S.O. article on that: stackoverflow.com/questions/5013281/…. Also see developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView Commented May 13, 2019 at 22:57
  • I will definitely, look into that, thanks! Commented May 13, 2019 at 23:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.