Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

112
Visualizações
Hugo and js. Add Title to header on scroll

On my static Hugo website I need the word "Critique" in the bottom of my sticky header on List.html page of the critique section and on the single.html of the section before scrolling. But on scrolling I would like to add the article title only on the single.html page but not on the list.html page. This is the logic I need somewhere in my partials/page-title.html

    {{ $page-scroll := "no-scroll" }}
    <script>
        $(window).on("scroll", function () {
        if ($(this).scrollTop() > 150) {
            ${page-scroll} = "scroll";
        }}
    </script>
    
    <section class="page-title">
      <div class="container">
        <div class="row">
          <div class="col-10">
          {{ if eq .Section "critique" }} <h3>Critique {{ if eq $page-scroll "scroll" }} / {{ .Title}} {{end}}</h3> {{ end }}
         </div>
        </div>
  </div>
</section>

Unfortunately the script doesn't change $page-scroll variable. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hugo variables are referenced like this:

{{ $page-scroll }}

However, you are looking for something like this:

<script>
    $(window).on("scroll", function () {
    if ($(this).scrollTop() > 150) {
        document.getElementById('showme').style.display = 'inline';
    }}
</script>

{{ if eq .Section "critique" }} 
  <h3>Critique<span id="showme" style="display: none;"> / {{ .Title}}</span></h3>
{{ end }}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda