2019-07-11, 02:52 AM
Uncaught TypeError: Cannot read property 'offsetTop' of null
Lines of offsetTop:
// -->
// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the header
var header = document.getElementById("myHeader");
// Get the offset position of the navbar
var sticky = header.offsetTop;
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
I did this by following this guide to get a sticky header: https://www.w3schools.com/howto/howto_js...header.asp
When using https:// -- There is an icon showing in the URL box of chrome and it says:
https://gyazo.com/4c1a5509b4f47c150e056c4cbeb820ce
Lines of offsetTop:
// -->
// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};
// Get the header
var header = document.getElementById("myHeader");
// Get the offset position of the navbar
var sticky = header.offsetTop;
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
I did this by following this guide to get a sticky header: https://www.w3schools.com/howto/howto_js...header.asp
When using https:// -- There is an icon showing in the URL box of chrome and it says:
https://gyazo.com/4c1a5509b4f47c150e056c4cbeb820ce