Advertisement
Femn0X

main javascript

Apr 29th, 2025 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.58 KB | Software | 0 0
  1. document.addEventListener('DOMContentLoaded', function() {
  2.   const footer = document.querySelector('footer');
  3.   if (!footer) {
  4.     console.error('Footer element not found. Please ensure your footer has a <footer> tag.');
  5.     return;
  6.   }
  7.  
  8.   let isFooterVisible = false;
  9.   const footerHeight = footer.offsetHeight;
  10.   const scrollThreshold = 800; // Adjust this value to control when the footer starts moving
  11.  
  12.   function handleScroll() {
  13.     const scrollPosition = window.scrollY || window.pageYOffset;
  14.     const windowHeight = window.innerHeight;
  15.     const documentHeight = document.documentElement.scrollHeight;
  16.  
  17.     // Check if the user has scrolled past a certain point and the footer isn't already fully visible
  18.     if (scrollPosition > scrollThreshold && !isFooterVisible) {
  19.       // Calculate the target bottom position to make the footer fully visible
  20.       const targetBottom = 0;
  21.  
  22.       // Use a smooth animation for the transition
  23.       let currentBottom = parseFloat(getComputedStyle(footer).bottom) || -footerHeight;
  24.       let animationInterval = setInterval(() => {
  25.         currentBottom += 5; // Adjust the step value to control the speed of the animation
  26.         footer.style.bottom = `${Math.min(currentBottom, targetBottom)}px`;
  27.  
  28.         if (currentBottom >= targetBottom) {
  29.           clearInterval(animationInterval);
  30.           isFooterVisible = true;
  31.         }
  32.       }, 15); // Adjust the interval to control the smoothness of the animation
  33.     } else if (scrollPosition <= scrollThreshold && isFooterVisible) {
  34.       // If the user scrolls back up, slowly hide the footer
  35.       const targetBottom = -footerHeight;
  36.       let currentBottom = parseFloat(getComputedStyle(footer).bottom) || 0;
  37.       let animationInterval = setInterval(() => {
  38.         currentBottom -= 5; // Adjust the step value to control the speed of the animation
  39.         footer.style.bottom = `${Math.max(currentBottom, targetBottom)}px`;
  40.  
  41.         if (currentBottom <= targetBottom) {
  42.           clearInterval(animationInterval);
  43.           isFooterVisible = false;
  44.         }
  45.       }, 15); // Adjust the interval to control the smoothness of the animation
  46.     }
  47.   }
  48.  
  49.   // Attach the scroll event listener to the window
  50.   window.addEventListener('scroll', handleScroll);
  51.  
  52.   // Initially position the footer off-screen
  53.   footer.style.bottom = `-${footerHeight}px`;
  54. });
  55. function main(){
  56.   const inp=document.getElementById("inp");
  57.   const output=document.getElementById("out");
  58.   if (inp && output){
  59.     output.textContent=inp.value;
  60.   }else{
  61.     console.error("Ein element wurde nicht gefunden")
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement