【发布时间】: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