-
-
Save jasonwilliamsau/5a9976152c81048b9c40e6deb582d2ae to your computer and use it in GitHub Desktop.
addEventListener to disable scroll on click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" dir="ltr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>test event listener</title> | |
<style> | |
section { | |
height: 150vh; | |
background-color: #0c0; | |
} | |
.tabs { | |
background-color: #c00; | |
display: flex; | |
justify-content: space-between; | |
padding: 1rem; | |
} | |
.tab { | |
background-color: #00c; | |
width: 150px; | |
height: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<section> | |
<div class="tabs"> | |
<div class="tab"></div> | |
<div class="tab"></div> | |
<div class="tab"></div> | |
<div class="tab"></div> | |
<div class="tab"></div> | |
</div> | |
</section> | |
<script> | |
let tabs = document.querySelector('.tabs'); | |
tabs.addEventListener('click', disableScroll); | |
function disableScroll(){ | |
document.body.style.overflow = 'hidden'; | |
console.log('scroll disabled'); | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment