Hide class when refreshing site and scroll

I’m very new to this and I am trying to add a button to a header when scrolling 355 px.

This is my code:

document.addEventListener('DOMContentLoaded', function() {
$(document).scroll(function() {
    var y = $(this).scrollTop();
    if (y > 355) {
    } else {
        display: none;

When I refresh the page, it gets reset. How can I make it not visible on refresh and make it visible as soon as I have scrolled 355 px?



Check your html code. I think you have missed to add class ‘button-hidden’ on initail render.

your code should be like follows when page render first time

<div id="categorymenu" class="button-hidden">
    <button value="save">save</button>