NextJS: Vanilla JavaScript, Possible or not?

Viewed 1808

Newbie to ReactJS and NextJS here, was wondering if it is possible to add JavaScript to HTML classNames in NextJS. For example trying to create a parallax effect requires a certain package to be installed through npm to be able to get parallax working.

Example question: How do I add a javascript effect to this image code?

<Image className={styles.bg}
    src="/../public/bg.jpg"
    // width={2049}
    // height={2049}
    // objectFit="cover"
    layout="fill"
    quality={100}
  />

So my question is how do I add the below code to make my javascript effect work:

let bg = document.getElementById("bg");

    window.addEventListener('scroll', function() {
      var value = window.scrollY;

      bg.style.top = value * 0.5 + 'px';
      moon.style.left = -value * 0.5 + 'px';
0 Answers
Related