Skip to content

Instantly share code, notes, and snippets.

@alexandreramosdev
Created September 4, 2018 03:58
Show Gist options
  • Save alexandreramosdev/4f7239768c1eabcd897c6973f9d68d3b to your computer and use it in GitHub Desktop.
Save alexandreramosdev/4f7239768c1eabcd897c6973f9d68d3b to your computer and use it in GitHub Desktop.
window.onscroll = () => stickyMenu() // chamar função ao move o scroll
const sticky = '104'
const $navigation = document.querySelector('.navigation')
const $logo = $navigation.querySelector('.navigation__logo')
const $links = $navigation.querySelectorAll('.navigation__link')
function stickyMenu () {
if (window.pageYOffset >= sticky) { // => comparar se o scroll é maior que o topMenu
$navigation.classList.add('--fixed') // => add class para fixar menu top
$logo.setAttribute('src', 'img/svg/logotipo-exemplo-white.svg')
$links.forEach(link => {
link.classList.add('--color')
})
} else {
$navigation.classList.remove('--fixed')
$logo.setAttribute('src', 'img/svg/logotipo-exemplo-green.svg')
$links.forEach(link => {
link.classList.remove('--color')
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment