Sticky Top on Scroll
Menu Sticky Top on Scroll
 

Sticky Top on Scroll

This page needs debugging

The implementation originally on the Parish Council website was a Top of page on the fixed bottom, bar menu. While this display of the button (menu item) worked well I needed to write a function to hide the menu item after the menu item was clicked.

The code for the onscroll Event was taken from the W3C example and I have another example where the W3C code is demonstrated.

What I trying to do here

Is to have a "Go-to-top" button that is both sticky and initially hidden until the screen is scrolled by a determined amount

Top

The control code for the button

The script that I developed for the Parish Counil page was a combination of the code for the conditional display of the Hamburger Menu on the Fixed Bottom Menu template. The link here is to an old layout but it shows the operation of the bottom menu and the hamburger when viewed on a mobile.

The script is a little more complex than the one I first tried on this page. The logic involves a Logical OR and the === operator. The code is deconstructed bere

The logic for the second scroll test page contains code that I have not yet tried to decode. The Javascript that manipulates the Document Object uses a document.object variable and then re-assigns the variable.className to a new value.

The getElementById() method is used to assign the variable x and this is compared to the value for a hidden and a displayed object.

The === Operator

freecodecamp.org say:

The == operator performs a loose equality comparison that performs type coercion if necessary to make the comparison possible.

The === operator, on the other hand, performs a strict equality comparison that does not perform type coercion and requires the operands to have the same type (as well as the same value).

Links

Top

References: - a note on these

  • The difference between == and === operators - https:// www.freecodecamp.org/news/ loose-vs-strict- equality-in-javascript
  • getElementById() method - https:// developer.mozilla.org/en-US/search? q=getElementById

Site design by Tempusfugit Web Design -