Skip to content

Instantly share code, notes, and snippets.

@jasonwilliamsau
Created August 24, 2021 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwilliamsau/5a9976152c81048b9c40e6deb582d2ae to your computer and use it in GitHub Desktop.
Save jasonwilliamsau/5a9976152c81048b9c40e6deb582d2ae to your computer and use it in GitHub Desktop.
addEventListener to disable scroll on click
<!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