Why is the child's CSS hover not functioning when the body has an event listener attached to it?

Check out the repository link here: https://codepen.io/Jaycethanks/pen/WNJqdWB

I am trying to achieve a parallax effect on the body and image container, as well as a scale-up effect on images when hovered over. However, the hover functionality is not working as expected. The body has an event listener attached.

<body>
  <div class="box">
    <div class="inner-box">
      <!-- prettier-ignore -->
      <div class="items-wrapper">
        <div class="box-item">
          <img src:'xxx'/>
.......

.box-item:hover {
  transform: scale(1.5) translateZ(50px);
  transition: 0.1s all ease;
}
  body.addEventListener("mousemove", (e) => {
    const { pageX, pageY } = e;
    setPointerPosition(pageX, pageY);
    const [xCent, yCent] = computedPointerPositionPercent(pageX, pageY, 12);
    // 50 is based on background-position: 50% 50% for changes

    body.style.backgroundPosition = `${xCent + 50}% ${yCent + 50}%`;
  });

Answer №1

After removing the body.addEventListener code, everything started working as expected. It seems that the issue was related to always hovering over centerPointerDot.

Instead of using body.addEventListener solely for changing the cursor image, consider achieving the same effect using CSS and the cursor property:

body.custom-cursor {
  cursor:url(http://www.example.com/custom-cursor.gif), auto;
}

Read more here

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to adjust the dimensions of an element so that it only fills the size of the initial window or

I need help keeping a specific element at the initial 100% height of the viewport, without it resizing when the user changes their window size. Should I use JavaScript to determine the initial viewport height and then pass those dimensions to the CSS? Can ...

Inquiring about building a comprehensive AJAX website: SEO, Google index, design templates

I'm currently developing a fully AJAX-based website. My focus right now is on implementing page navigation and content display without the need for page reloading. Here's my approach: <html> <head> <!--CSS--> .hidde ...

Tips for integrating map coordinates into a URL

In my React app, there is a Leaflet map that I want to update the URL dynamically with position information (latitude, longitude, and zoom) whenever the map is moved. For example: app.com/lat,lng,z/myroutes Furthermore, default values for lat, lng, z sho ...

What is the reason for instanceof Map returning false?

Utilizing the Draft.js plugin called Mention. When accessing editorState.content.entityMap.mention, I am able to retrieve the value by: mention.get('address') However, when I attempt to verify if it is a Map using: console.log('mention&a ...

Am I going too deep with nesting in JavaScript's Async/Await?

In the process of building my React App (although the specific technology is not crucial to this discussion), I have encountered a situation involving three asynchronous functions, which I will refer to as func1, func2, and func3. Here is a general outline ...

Receiving a blank array upon calling res.json() in Node.js script

I'm facing an issue with my code snippet that displays all posts, including the username and display picture of each user. Everything seems to be working fine as the log output is perfect. However, I'm struggling to return this data as a JSON obj ...

Complications arising from IE when using strict doctype with CSS and jQuery

Here's the code I'm using for a sliding caption effect on my gallery site: I specifically implemented the last effect which is the Caption Sliding (Partially Hidden to Visible). $('.boxgrid.caption').hover(function(){ $(".cover", th ...

Ways to create an object based on another object

Currently, I am teaching myself Javascript. My focus is on working with Vuejs and express for a CRUD App. In one of my components, I retrieve data from my backend using the API: localhost:3000/api/transport. The response contains all objects from the data ...

Using AngularJS to bind a dynamically created form built in JavaScript

I am looking to dynamically build a form using JavaScript and utilize it within an AngularJS form controller. In the example provided below, the form is not rendering as HTML, and I aim to bind it to the model variable. http://jsfiddle.net/g6m09eb7/ ...

What is causing the premature termination of the for loop?

I am currently utilizing Node.js (with nodemon as the server) to upload an excel file, parse its contents, and then send each row to a MongoDB database. The total number of rows in the array is 476, however, the loop seems to stop at either 31 or 95 withou ...

Ways to retrieve the index of an element with a certain class

When I click on an item with a specific class, I want to retrieve its index within that class only. <div class="gallery"> <div class="gallery-item"></div> <div class="gallery-item"></div> <div class="gallery-item ...

The concept of matryoshka logic applied to data manipulation

"mainData"{ entities:[] }, "data2":{ entities:[ { name:"mainData": //entites }, { name:"mainData": //entites }, { name:"m ...

Monitor changes in the ID attribute and ng-model using $watchCollection

My goal is to utilize the $watchCollection feature in my directive to monitor two specific elements. The first element is the ng-model. The second element is the id attribute. I have successfully implemented separate watches for each of them. retur ...

Organize the Div elements in the form of a message

Here is the code I am working with: https://jsfiddle.net/bdqgszv5/1/ This is the same code without jsfiddle: <section id="aussteller" class="row separated"> <div class="section-header text-center"> <h2& ...

Retrieve client-side environment variables

When making multiple API calls within my components using the fetch method, I found myself constantly having to determine which environment I was in. To streamline this logic, I created a Utils class that provides the appropriate base URL: export default c ...

(Definition) What is the proper way to reference a variable inside another variable?

Currently, my project is using inconsistent terminology when referring to variables, and I need to clarify this issue. Let's take an object defined in this way: var anObject = { a: { value1: 1337, value2: 69, value3: "420 ...

Utilizing an Image as a Link in the Background

I am working on a way to convert the CSS background image I have into a clickable link that can be referenced. Here is my CSS code: #wrapper { height: 100%; padding: 66px; } #ad_11 { background-image: url(images/index1.png); display: block; text-indent: ...

Is there a way to shut down a browser tab without being asked, "Are you sure you want to close this window"?

Is there a way to gracefully close a browser window without being interrupted by the annoying Do you want to close this window prompt? I've noticed that whenever I attempt to use the window.close(); function, this prompt always pops up. ...

Receiving an error stating that .startsWith() is not a function in react native

I'm having trouble searching for items using a search bar. The original items are in 'prod', but I keep encountering errors such as 'startsWith() is not a function' and sometimes '.toLowerCase() is not a function'. const ...

JavaScript may encounter undefined JSON data after receiving a response from the server

I am facing an issue with my PHP script that is supposed to receive a JSON array. Here is the code I am using: $(function() { $("img").click(function() { auswahl = $( this ).attr("id"); $.get('mail_filebrowser_add2.php?datenID=' + aus ...