Updating the Scale of the Cursor Circle on my Portfolio Site

I attempted to find tutorials on creating a unique circle cursor that can hide the regular mouse cursor as well.

After implementing it with a difference blend mode, I encountered an issue where I wanted the scale to change when hovering over a link.

The problem arose because it failed to recognize and scale up when a <a> tag was nested inside a <div>.

I also require a smooth transition of 0.1s upon hover enter and exit for a seamless effect.

Your assistance would be immensely appreciated as I aim to complete this website in the coming months.

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="portfolio" content="portfolio">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Meskhi Graphics</title>
        <link rel="icon" type="image/x-icon" href="/assets/Favicon.ico">
        <link rel="stylesheet" href="/css/styles.css">
        <link rel="stylesheet" href="/css/mediaqueries.css">
    </head>
    <body>
        <div class="a1">
                <img class="icon" src="/assets/meskhi_graphics_logo.svg">
        </div>
        <div class="a2">
            <ul class="skills">
                <li class="social_media">Social Media <br>Marketing Manager</br></li>
                <li class="graphic_designer">Graphic Designer</li>
                <li><a href="#">UI/UX Designer</a></li>
            </ul>
            <p class="about_me">Hey, Ich bin David und komme aus Kalrsruhe.<br>
                Beruflich bewege ich mich in der Welt des Grafikdesign<br>
                und UI/UX Designs. Derzeit stecke ich mitten in einer<br>
                Weiterbildung zum Social Media Marketing Manager.
            </p>
        </div>
        <h1><a href="#">Hallo</a></h1>
        <div class="a3"></div>
        <div class="cursor"></div>
        <script src="script.js" async defer></script>
    </body>
</html>

CSS:

@import url(/css/satoshi.css);

* , *::before, *::after{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Satoshi-Variable;
}

html,body{
height:100%;
 min-height:100%; 
}

body {
    background-color: #f0efe9;
    height: 100vh;
    width: 100%;
    cursor: none;
}

a {
    cursor: none;
    text-decoration: none;
    color: #0f1016;
}

div {
    border-spacing: 0;
    display: block;
}

.a1 {
    width: 50%;
    height: 25%;
}

.a2 {
    width: 60%;
    height: 50%;
}

.a3 {
    width: 50%;
    height: 25%;
}

.icon {
    padding: 5% 0 5% 10%;
    max-width: 40%;
}

.skills {
    font-family: Satoshi-Variable;
    font-weight: 600;
    font-size: 2em;
    padding-left: 10%;
    padding-top: 2%;
    padding-bottom: 2%;
    color: #0f1016;
}

.graphic_designer {
    margin-top: 2%;
    margin-bottom: 2%;
}

ul {
    list-style: none;
}

.about_me {
    padding-left: 10%;
    line-height: 2em;
    color: #0f1016;
}

.cursor{
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: fixed;
    transform: translate(-50%, -50%);
    pointer-events: none;
    background: #f0efe9;
    mix-blend-mode: difference;
}

a:hover ~ .cursor{
    transform: translate(-50%, -50%);
    height: 80px;
    width: 80px;
    transition: width 0.1s linear, height 0.1s linear;
}

JS:

const cursor = document.querySelectorAll(".cursor");

window.addEventListener("mousemove", (e) => {
  let x = e.pageX;
  let y = e.pageY;
  let path = e.composedPath();
  
  cursor.forEach(el => {
    el.style.left = `${x}px`;
    el.style.top = `${y}px`;
    
    links.forEach(link => {
      link.addEventListener("mouseenter", () => {
        el.classList.add("hover");
      })
      link.addEventListener("mouseleave", () => {
        el.classList.remove("hover");
      })
    })
    
  })
  
})

Trying to swap out the <a> tag with an <h1> outside a div didn't produce the desired result, showing limitations.

Answer №1

When hovering, simply apply the class to the cursor for the desired effect.

.cursor.hover {
    transform: translate(-50%, -50%);
    height: 80px;
    width: 80px;
    transition: width 0.1s linear, height 0.1s linear;
}

Alternatively, achieve the same result using CSS only.

const cursor = document.querySelector(".cursor");

window.addEventListener("mousemove", (e) => {

  /* 
    Correct a bug by accounting for scroll position
    Subtract scroll position for accuracy with fixed elements
  */

  let x = e.pageX - window.scrollX;
  let y = e.pageY - window.scrollY;

  cursor.style.left = `${x}px`;
  cursor.style.top = `${y}px`;
});
.cursor{
    height: 40px;
    width: 40px;
    border-radius: 50%;
    position: fixed;
    transform: translate(-50%, -50%);
    pointer-events: none;
    background: #f0efe9;
    mix-blend-mode: difference;
}

body:has(a:hover) .cursor{
    transform: translate(-50%, -50%);
    height: 80px;
    width: 80px;
    transition: width 0.1s linear, height 0.1s linear;
}
<div class="cursor"></div>

<a href="#">FOOOOOOO</a>
<br/><br/><br/><br/>
<a href="#">FOOOOOOO</a>
<br/><br/><br/><br/>
<a href="#">FOOOOOOO</a>
<br/><br/><br/><br/>
<a href="#">FOOOOOOO</a>
<br/><br/><br/><br/>
<a href="#">FOOOOOOO</a>

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 ensure the website title is displayed properly on a mobile browser?

Concern I have been encountering difficulties while constructing a portfolio website using bootstrap 5. The issue arises with the navbar, causing the Title to overlap the hamburger menu and extend beyond the edge of the screen. Strangely enough, this prob ...

troubleshooting Axios errors in React applications

User/Project.js: import React, { useState, useEffect } from "react"; import Axios from "axios"; const Project = () => { const [projectName, setprojectName] = useState(""); const [projectDescription, setprojectDescriptio ...

Reach out to individuals who have responded to a message on Discord using JavaScript

I am looking to develop a script that will enable me to send direct messages to users who have reacted (all reactions) to a specific message by its ID. I want to exclude bots and ensure that each user only receives one message even if they react multiple ...

I am retrieving data from a service and passing it to a component using Angular and receiving '[object Object]'

Searching for assistance with the problem below regarding my model class. I've attempted various approaches using the .pipe.map() and importing {map} from rxjs/operators, but still encountering the error message [object Object] export class AppProfile ...

The data in my JSON string is not fully received through the HTTP GET request

Whenever I send my array to the PHP file, it receives incomplete data. The content of my 'arr' variable is as follows: [["╪▒┘à┘╛┘╪د","67126881188552864","Empty,Empty,Empty,Empty,8644,-360,-4,8691,-3.48,-313,1015,4.334 M,1392/12/2 ...

ReactJS is encountering a situation where two children are using the same key and causing

When I try to view the profile information of another user, I encounter a duplicate key error that says: "Warning: Encountered two children with the same key, ``. Keys should be unique so that components maintain their identity across updates. Non-unique k ...

Issues with external javascript link functionality

I'm having trouble connecting my external JavaScript file to my HTML code. I'm attempting to concatenate two strings using an input function and then display the new string in the empty text field. What could be causing this issue? Appreciate an ...

In Angular 10, the custom CSS URL is loading after the standard styles.css file

Below is the configuration from my angular.json file: "options": { "outputPath": "dist/example", "index": "src/index.html", "main": "src/main.ts", ...

Is a Toolbar plugin or custom Toolbar options the better choice for your project?

Could anyone recommend a Jquery plugin for adding a ToolBar option to my web application? I've searched and researched for the past 48 hours but haven't found a reliable one yet. If the recommended toolbar resembles the image below, that would b ...

Chrome's XPath attribute selection is not functioning properly

After running a small test with expect.js, here are the results: describe('xpath', function () { it('locates attribute nodes', function () { $(document.body).append('<string fooBar="bar"><data id="xyz">< ...

``Considering the compatibility issues with position: absolute in Internet Explorer 8

Here's an example snippet of code in HTML: <form> <input type="file" id="iefile"> </form> <form> <input type="file" id="iefile"> </form> This is how it looks with some CSS styling: form{ position:rela ...

Error: Reference 'ref' is undefined in the 'no-undef' context. I am interested in experimenting with loading images from Firebase storage

While working with React, I encountered an issue when trying to fetch an image URL from Firebase Storage and display the image. The error 'ref' is not defined (no-undef) occurred. https://firebase.google.com/docs/storage/web/create-reference Th ...

Get a collection of images packed into a single zip file

My current function downloads multiple images and saves them to a user's "download" folder, although it only works in Chrome. I am looking to enhance this function by combining the downloaded images into a single zip file. Below is my existing code. ...

Buttons with a slight lean towards the edge

The alignment of these buttons within their container is not what I desire. They are currently floating to the left, which is a result of the float: left; attribute applied to them. I tried removing the float: left; and instead used text-align: center; on ...

Steps for inserting an array of strings in PHP into HTML input fields

I need help with extracting elements from a php array and displaying them as a list of text input fields on a webpage. The issue I'm facing is that the elements in the $list are strings, and when I run the code, only the portion of the string up to th ...

Using Selenium Webdriver with C# to dynamically expand a RadMenu Webelement in Javascript

I am currently working with Selenium WebDriver in C# and facing an issue with a RadMenu. My goal is to hover over the menu so that it expands a sub menu, where I can find a specific webelement to click. I have tried using JavaScript for this purpose, but u ...

Using anchor tags to send HTML code through email

I currently have an anchor tag on my website that looks like this: <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e0d11131b11101b3e0d11131b09161b0c1b501d1113">[email protected]</a>?subject=Wel ...

Mix div borders with varying border radius for child elements

I'm currently working on a project that involves creating border lines between divs to achieve a design similar to the one shown in this design jpeg. However, I've only managed to reach an output jpeg where the merging is not quite right. The C ...

Using JavaScript to display dynamic data pulled from Django models

I am currently in the process of designing my own personal blog template, but I have encountered a roadblock when it comes to creating a page that displays previews of all posts. This particular page consists of two columns, #content-column-left and #conte ...

Executing Selenium tests: utilizing the webdriver.wait function to repeatedly call a promise

Currently, I am using Selenium ChromeDriver, Node.js, and Mocha for testing purposes... I am facing a dilemma at the moment: The driver.wait function seamlessly integrates with until. I have a promise, which we'll refer to as promiseA. This pro ...