sticky operations in javascript
var siteHeader = document.getElementById('siteHeader'),
siteNav = document.getElementById('siteNav');
window.onscroll = function() {
if ( siteNav.offsetTop < document.documentElement.scrollTop + 26 || siteNav.offsetTop < document.body.scrollTop + 26) {
siteHeader.setAttribute("class","sticky");
}
else {
siteHeader.setAttribute("class","");
}
}
nav {
position:sticky;
top:0;
}
/*Top can be replaced with bottom, left, or right
depending on what you want :) */
Also in JavaScript:
- how to print the value of variable in javascript in html
- sum array without loop javascript
- switch statement in javascript
- owl carousel json not working
- stopwatch with javascript
- js find place value
- usereduce
- js getelementbyid
- convert string to char array javascript
- mock sqs.sendMessage node js
- modern javascript for loop syntax
- jquery toggle show hide
- how to create a component in react native
- javascript object entries
- how to deploy react app firebase
- jquery test div exists
- addItem(item) js
- dark mode with react hooks
- Create React App command
- dom create element
- set attribute javascript background image
- regular expression match text between quotes
- how to get user ip address in javascript
- inject image javascript