我自己想做一個 demo,使用了 vh 來定義了 4 個 section,然后想在滾動的時候顯示對應的 a 錨點鏈接的背景顏色。請問實現的思路是怎么樣的呢?以及有關的 js 代碼。。我在鼠標點擊中使用了錨點來進行跳轉,但是關于滾動條滾動時的 scrollTop 不能使用 vh,所以我很想搞明白使用什么方式來實現,其中我也想用到 classList 來 toggle 其中對應的 class,但是代碼我卻想不出來。謝謝各位。HTML:<section id="bar-1" style="width: 100vw; height: 100vh; background: pink"></section>
<section id="bar-2" style="width: 100vw; height: 100vh; background: red">
</section><section id="bar-3" style="width: 100vw; height: 100vh; background: dodgerblue">
</section><section id="bar-4" style="width: 100vw; height: 100vh; background: purple"></section><div id="bar">
<ul>
<li><a href="#bar-1" class="active"></a></li>
<li><a href="#bar-2"></a></li>
<li><a href="#bar-3"></a></li>
<li><a href="#bar-4"></a></li>
</ul></div>效果圖:
關于vh的滾動條事件
喵喔喔
2018-10-10 13:22:34