Check if `menu` exists before using scroll position logic

This commit is contained in:
Aditya Telange 2021-10-30 20:01:35 +05:30
parent b8c7df1ef9
commit 76ea33c89c
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77
1 changed files with 5 additions and 3 deletions

View File

@ -25,10 +25,12 @@
<script> <script>
let menu = document.getElementById('menu') let menu = document.getElementById('menu')
if (menu) {
menu.scrollLeft = localStorage.getItem("menu-scroll-position"); menu.scrollLeft = localStorage.getItem("menu-scroll-position");
menu.onscroll = function () { menu.onscroll = function () {
localStorage.setItem("menu-scroll-position", menu.scrollLeft); localStorage.setItem("menu-scroll-position", menu.scrollLeft);
} }
}
document.querySelectorAll('a[href^="#"]').forEach(anchor => { document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", function (e) { anchor.addEventListener("click", function (e) {