En mi sitio web, tengo un encabezado adhesivo y una sección de pestañas adhesivas. La sección particular de esas pestañas respectivas cuando desplazamos esa sección se esconde debajo del encabezado y las pestañas adhesivas, he usado Javascript para hacer esto. Quiero que las secciones aparezcan justo después de las pestañas adhesivas, que ahora se abren un poco debajo de las pestañas adhesivas.
Hay un problema con la altura del encabezado y las pestañas adhesivas.
Quiero el script en el que la sección se desplazará preguntándose las alturas del encabezado y las pestañas adhesivas, para que se vea correctamente.
A continuación se muestra el script que he utilizado.
//script for sticky section like tabs starts // Click event offset = 0; $('#primary-navwrapper li a[href^="#"]').click(function(event) { // Prevent from default action to intitiate event.preventDefault(); //remove active from all anchor and add it to the clicked anchor $('#primary-navwrapper li a[href^="#"]').removeClass("active") $(this).addClass('active'); // The id of the section we want to go to var anchorId = $(this).attr('href'); // Our scroll target : the top position of the section that has the id referenced by our href var target = $(anchorId).offset().top - offset; console.log(target); $('html, body').stop().animate({ scrollTop: target }, 600, function () { window.location.hash = anchorId; }); return false; }); //check the pages when scroll event occurs $(window).scroll(function(){ // Get the current vertical position of the scroll bar position = $(this).scrollTop(); $('#primary-navwrapper li a[href^="#"]').each(function(){ var anchorId = $(this).attr('href'); var target = $(anchorId).offset().top - offset; // check if the document has crossed the page console.log(position,target); if(position>=target){ //remove active from all anchor and add it to the clicked anchor $('#primary-navwrapper li a[href^="#"]').removeClass("active") $(this).addClass('active'); } }) }) $(function(){ //set our scroll state after dom ready $(window).scroll(); }) //script for sticky section like tabs ends