【问题标题】:Hugo and js. Add Title to header on scroll雨果和 js。在滚动时将标题添加到标题
【发布时间】:2021-12-15 15:53:36
【问题描述】:

在我的静态 Hugo 网站上,在滚动之前,我需要在评论部分的 List.html 页面和该部分的 single.html 上的粘性标题底部添加“Critique”一词。但是在滚动时,我只想在 single.html 页面上添加文章标题,而不是在 list.html 页面上。这是我在 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>

不幸的是,脚本没有改变 $page-scroll 变量。我做错了什么?

【问题讨论】:

    标签: javascript html hugo


    【解决方案1】:

    Hugo 变量是这样引用的:

    {{ $page-scroll }}
    

    但是,您正在寻找这样的东西:

    <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 }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-09
      • 2019-06-12
      • 1970-01-01
      • 2020-03-29
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多