Create link to menu item of another page [closed]

1

Hello, I have the following page with a menu of services in the middle of it like this:

link

And when I click on a service, it changes the content on the right side, okay.

As I create on another page links that open this service page already direct in the services.

att

Richardy

    
asked by anonymous 03.07.2018 / 15:24

1 answer

0

You can put a hash #servicosN (where N is the link number) in the URL and use window.scrollTo to scroll the screen to the menu and fire a click on the menu link. Link example:

http://www.clinvetimbituba.com.br/servicos.html#servicos1

And put this script on page servicos.html :

document.addEventListener("DOMContentLoaded", function(){
   var target = location.hash; // verifica se tem hash na URL
   var linq = $("ul.nav-tabs li a[href$='"+target+"']"); // link que contém a hash
   if(target && linq.length){
      setTimeout(function(){
         // distância do menu ao topo menos altura do nav
         var top = $(".sidebar").offset().top - $("#main-nav").height();
         window.scrollTo(0, top); // rola atela até o menu
         linq.trigger("click"); // dispara o clique
      }, 500);
   }
});
    
03.07.2018 / 15:56