When the mouse hovers over an image, the custom cursor reverts to its default style

Currently, I'm in the process of developing a website that features custom cursors. These unique cursor designs change based on the background theme; however, an issue arises where the cursor defaults back to its original state when near or over the image of earth. Below is a snippet of my HTML code:

<div class="main-wrapper">
    <div class="season winter" data-background="#2b1055">Winter</div>
    <div class="season summer" data-background="#5988e2">Summer</div>
    <div class="season spring" data-background="#7cdea1">Spring</div>
    <div class="season autumn" data-background="#cf8a8a">Autumn</div>
</div>

<div class="wrapper">
    <div>
        <img id="earth" src="img/earth.png" alt="scroll">
    </div>
</div>

CSS Styling:

body {
  transition: background 1s ease-in-out;
}

.season {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  color: #fff;
  font-family: sans-serif;
  font-size: 72px;
  font-weight: 600;
  text-transform: uppercase;
  &[data-background="yellow"] { color: #333; };
}

.winter {
  cursor: url('img/winter-cursor.png'), auto;
}

.summer {
  cursor: url('img/summer-cursor.png'), auto;
}

.spring {
  cursor: url('img/spring-cursor.png'), auto;
}

.autumn {
  cursor: url('img/autumn-cursor.png'), auto;
}

.wrapper {
  top: 120%;
  left: 50%;
  transform: translate(-50%, -50%);
  position: fixed;
}

#earth {
  width: 800px;
  height: 800px;
} 

Javascript functions (for rotating earth animation and background alteration during scrolling):

// Rotating earth 
window.onscroll = function() {
  scrollRotate();
};

function scrollRotate() {
  let image = document.getElementById("earth");
  image.style.transform = "rotate(" + window.pageYOffset / 24 + "deg)";
}

// Background change 
window.sections = [...document.querySelectorAll('.season')];
window.lastScrollTop = window.pageYOffset;

document.body.style.background = window.sections[0].getAttribute('data-background');

window.addEventListener('scroll', onScroll);

function onScroll() {
  const scrollTop = window.pageYOffset;
  const section = window.sections
    .map(section => {
      const el = section;
      const rect = el.getBoundingClientRect();
      return {el, rect};
    })
    .find(section => section.rect.bottom >= (window.innerHeight * 0.5));

  document.body.style.transition = 'background 1s cubic-bezier(0.3, 0.3, 0.3, 0.3)';
  document.body.style.background = section.el.getAttribute('data-background');

}

I've attempted to resolve this issue by adjusting the positioning of elements within the HTML code, specifically by relocating the earth image downward. However, no solution seems to work effectively.

Moreover, I tested changing the cursor to "none" for #earth in the CSS file, but unfortunately, it resulted in the disappearance of the cursor altogether. Any feedback or suggestions regarding this matter would be highly valued. Thank you!

Answer №1

I trust that the response provided below meets your needs.

window.onscroll = function() {
  
  var getCurrentClassName =//write a snippet to retrieve class name depending on user's scroll;
  scrollRotate(getCurrentClassName);//"autumn"
  
};

function scrollRotate(seasonName) {
  let image = document.getElementById("earth");
  image.classList.replace(seasonName);
  image.style.transform = "rotate(" + window.pageYOffset / 24 + "deg)";
}

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

Defining colors in TinyCSS and GTK themes using the `@define-color

I've been working on a project that involves parsing GTK+3 themes using the TinyCSS library. However, it seems that TinyCSS is not recognizing lines such as @define-color base_color #FAFAFA; These definitions are stored in parser.styleSheets[0].er ...

Sending data from a JSP page to a database seamlessly without the need for page refresh

Currently, I am in the process of developing a web application using spring and hibernate to enhance my translation skills from Russian to English. One of the challenges I faced was in displaying all the questions retrieved from the database on a JSP pag ...

Unable to redirect using JQuery Ajax post after receiving an ActionResult from an MVC controller

I'm trying to send data from a method to an MVC controller that gives back an action result, and then have my site automatically navigate to the correct view. Here's the code snippet I'm currently working with: function RedirectFunction(ite ...

Prevent Copying, Defining, or Sharing in iOS Safari Selections

A Cordova App has been developed using Angular JS, with the Apple webview copy/share/define menu disabled from the view code in Xcode to prevent it from popping up. The Angular JS code is also available on a website accessible by desktops, where the Copy/ ...

The iPhone touch functionality is mimicking hover behavior within an HTML5 application

I am creating an HTML5 application using Bootstrap. I have implemented some custom markup to style radio buttons, as well as included JQuery for functionality: <div role="group" class="btn-group btn-group-justified"> <label for="radioOption1" ...

Is it possible to use the googleapis npm package to make a query to a googleSheet?

I have a huge dataset with thousands of rows and I want to optimize my queries instead of fetching all the data every time. I checked out the Query language but it doesn't quite fit my needs. For authentication, I am using a Service account: const au ...

Iterating through an array in a TypeScript for loop to handle undefined elements

Whenever I set an anonymous callback function on a REST service, I encounter a peculiar issue. If I simply use console.log to display the result of the service call, I am able to see the expected payload (an array of objects). However, when I attempt to it ...

What steps can I take to eliminate the warning "Warning: Prop `style` did not match" that appears when I bring in the Image component in Next.js?

Hi there! I'm encountering a warning when trying to import an image using the Image component in nextjs. The warning message reads: Warning: Prop style did not match. Server: "display: block; max-width: 100%; width: initial; height: initial; ba ...

Excessive padding observed on the right side of the screen when viewed on mobile devices

I am having an issue with my portfolio site where there is a white space on the right side in the mobile view, but only in Chrome. The desktop and Mozilla mobile views are fine. I have attached a screenshot highlighting the problem. Here is the link: Chrom ...

Experiencing issues launching the server.js file on Node.js while incorporating socket.io

Several months ago, I was able to successfully run this code without any issues. However, recently I have encountered some unexpected problems. This code is for a whiteboard app that can be viewed on this link. The current issue I am facing is that when ...

Use dots to bridge the gap between two text elements

Trying to find a way to automatically adjust spacing between two objects has been a challenge for me. Specifically, I am dealing with menu items and their corresponding prices. The desired outcome would look something like this: Burger................. ...

Ways to utilize this node.js module within a specific file

This is the third party node-js module I have created: var knox = require('knox') , Resource = require('deployd/lib/resource') , httpUtil = require('deployd/lib/util/http') , formidable = require('formidable') ...

How to extend the Bootstrap 4 navbar search box to fill the entire available space

I am currently designing a navigation bar using Bootstrap 4, with the following elements arranged from left to right: The Logo (brand) A search bar The website's navigation My aim is to have the search box stretch across the entire space available ...

Obtain every possible sequence of US phone number segments for a provided number

The format of a US phone number is as follows: (XXX) XXX-XXXX Given a string consisting only of digits with a length between 0 and 10, I want to generate an array of all possible chunks that match the US phone number format. For example: Input: "54" Out ...

Is there a more efficient method for writing my jQuery code that follows a step-by-step approach?

I have developed a step-by-step setup process that guides users through various sections. Instead of using separate pages for each step (like step1.php, step2.php, etc.), I have all the code contained in one page named setup.php. This is achieved by utiliz ...

Wait for the Selenium test to continue only when a specific element is visible on

<img style="width: 640; height: 640;" id="img108686545" alt="Loading Word War..." src="www.something.com/anu.jpg"> Is there a way to detect when this particular element is visible on the page? The value of the "id" attributes keeps changing with eac ...

"Utilizing JavaScript to filter JSON data at a deep nested

When working with a JSON data set, I often face the challenge of filtering based on specific child values. Take the following example: [ { "Date": "2017-03-02T00:00:00", "Matches": [ { "Id": 67, ...

Tips for customizing the selected and hover color of ListItem in Material UI

Having trouble getting the 'selected' or 'hover' colors to work for the ListItem component. I've tried setting its classes like this: <ListItem selected button key="home" classes={{ selected: classes.listItemSelected } ...

Creating an array in Angular is done by using the syntax []

I encountered an error and I'm not sure how to fix it. Can someone assist me? The error message reads: "Type '{ animal:[{ id : 1,name: "Elephant"},{id : 2, name: "Horse"} []; }' is not assignable to type 'string[]'. Property & ...

Menu options are neatly displayed alongside video player without any overlap

I have included an object tag in my page to play videos: <object id="Player" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" data="mms://TAL-BBSR-01/01_Debugging.wmv" width="100%" type="video/x-ms-asf" height="400" wmode="opaque" url="mms://TAL-BB ...