Jump to content
akaroot

Problema CSS/JS. Oare are cineva cunostintele necesare?

Recommended Posts

Incerc sa refac efectul de scroll al logoului de la gucci : https://www.gucci.com/ro/en_gb/

Dar Nu am reusit sa creez animatia nici cum ... exemplu : https://goiaandrei.com/

 

Am folosit codul de mai jos:

HTML:

<div id="stickyNav">
  GOIA
</div>

CSS:

#stickyNav {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.3s ease-in-out;
  z-index: 1000;
  font-size: 10vw; /* Initial large size */
  color: white;
  text-align: center;
  white-space: nowrap;
}

.isSticky {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 4vw; /* Smaller size when fixed */
  color: black;
}

JS:

document.addEventListener('DOMContentLoaded', function() {
  const nav = document.getElementById('stickyNav');
  let isSticky = false;

  function setStickyClass(sticky) {
    if (sticky && !isSticky) {
      nav.classList.add('isSticky');
      isSticky = true;
    } else if (!sticky && isSticky) {
      nav.classList.remove('isSticky');
      isSticky = false;
    }
  }

  window.addEventListener('scroll', function() {
    let scrollTop = window.pageYOffset || document.documentElement.scrollTop;

    if (scrollTop > 150) {
      setStickyClass(true);
    } else {
      setStickyClass(false);
    }
  });
});

Are cineva cunostintele necesare si bunavointa sa ma ajute? Nu mai stiu cum sa il invart sa functioneze...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...