Scroll to Hide Image Using css and Java
Publish: 14 March 2024, 6:00 pm IST | Views: 130
Page को Scroll करने से Image Hide हो जायेगा, या image की जगह पर आप कोई भी Code करें, लेकिन class="hide-scroll" करें
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selected Profiles</title>
<style>
.hide-scroll {
display: none;
position: fixed;
top: 20px;
left: calc(50% - 280px); /* 600px width + 20px left margin = 620px / 2 = 310px */
transition: opacity 0.5s ease-in-out;
max-width: 600px;
width: 100%;
margin: 0 auto;
}
.show {
display: block;
opacity: 1;
}
</style>
</head>
<body>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
<img src='https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' class="hide-scroll" title='Selected Profiles' alt='Selected Profiles' width='38px'/>
<script>
document.addEventListener('DOMContentLoaded', function () {
var image = document.querySelector('.hide-scroll');
window.addEventListener('scroll', function () {
if (window.scrollY > 20) {
image.classList.add('show');
} else {
image.classList.remove('show');
}
});
});
</script>
</body>
</html>
Categories: Coding
Tags: Scroll to Hide Image, Scroll to Hide, Scroll to Hide Code





