Sleek animation designed for a personalized cursor when hovering over an object

I'm currently working on improving the transition of the cursor for a smoother experience. Right now, the size abruptly changes when hovered over the target element. Any suggestions on how I can achieve a smoother increase in size, with a better animation than what is happening currently? Below is the current code snippet, along with a gif showcasing the current behavior: https://i.sstatic.net/E1v2Z.gif

<style>
.cursor {
    content: " ";
    position: absolute;
    background: #ffffff;
    width: 16px;
    height: 16px;
    border-radius: 100%;
    user-select: none;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 9999;
    transition: ease-in-out 0.3s;
}
</style>

 <div class="cursor"><span id="myspan"></span></div>

    <script>
        var cursor = document.querySelector('.cursor');
        document.addEventListener('mousemove', (e) => {
            cursor.style.left = e.pageX + 'px';
            cursor.style.top = e.pageY + 'px';
        });

    </script>


 <div class="div-33">
        <a href="" class="a1" style="cursor:none">
            <span class="span-11 cursorHover div-34">
                LET’S GET SOMETHIN’
                <br />
                COOKIN’.
                <img src="imgs/im/Vector.png" class="arrow mt-4" />
            </span>
        </a>
    </div>

    <script>
        var cursor3 = document.querySelector('.cursorHover');
        span = document.getElementById("myspan");
        txt = document.createTextNode("Say hi!");

        cursor3.addEventListener('mouseenter', () => {
            var element = document.querySelector('.cursor');
            element.style.transform = 'scale(6)';
            element.style.background = '#FF6E1D';
            span.appendChild(txt);
        });

        cursor3.addEventListener('mouseleave', () => {
            var element = document.querySelector('.cursor');
            element.style.transform = '';
            element.style.background = '';
            span.removeChild(txt);
        })

    </script>

Answer №1

Utilize the

transition:all ease-in-out 0.25s;
code to create a smooth transition effect for all properties within a time frame of 0.25s, incorporating the ease-in-out speed curve. Explore more options and details here.

To prevent unwanted scrollbars caused by cursor positioning, I have set the cursor position to fixed.

var cursor = document.querySelector('.cursor');
document.addEventListener('mousemove', (e) => {
  cursor.style.left = e.pageX + 'px';
  cursor.style.top = e.pageY + 'px';
});

var cursor3 = document.querySelector('.div-33');
span = document.getElementById("myspan");
txt = document.createTextNode("Say hi!");

cursor3.addEventListener('mouseenter', () => {
  var element = document.querySelector('.cursor');
  element.style.transform = 'scale(6)';
  element.style.background = '#FF6E1D';
  span.appendChild(txt);
});

cursor3.addEventListener('mouseleave', () => {
  var element = document.querySelector('.cursor');
  element.style.transform = '';
  element.style.background = '';
  span.removeChild(txt);
})
.cursor {
    content: " ";
    position: fixed;
    background: #ffffff;
    width: 16px;
    height: 16px;
    border-radius: 100%;
    user-select: none;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 9999;
    transition:all ease-in-out 0.25s;
    transform-origin: top left;
}
<div class="cursor"><span id="myspan"></span></div>;

 <div class="div-33">
        <a href="" class="a1" style="cursor:none">
            <span class="span-11 cursorHover div-34">
                LET’S GET SOMETHIN’
                <br />
                COOKIN’.
                <img src="imgs/im/Vector.png" class="arrow mt-4" />
            </span>
        </a>
    </div>

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

While attempting to upload a file in my Mocha Node.js test, I encountered the message: "Received [Object null prototype] { file: { ... }}"

Everywhere I find the solution in white : app.use(bodyParser.urlencoded({extended: true})); I can use JSON.stringify(req.files) However, I am sure there is a way to fix my problem. My Mocha test : it('handles file upload', async function () { ...

Having trouble with Vue 3 Composition API's Provide/Inject feature in Single File Components?

I am currently developing a VueJS 3 library using the Composition API. I have implemented Provide/Inject as outlined in the documentation. However, I am encountering an issue where the property in the child component remains undefined, leading to the follo ...

"Create a new row in the list by selecting an option from the drop-down

I'm experimenting with the following scenario. There is a function that reveals a hidden list based on a dropdown selection. To see it in action, please click here. What I am aiming to achieve is for Option1 to display the content of #List-Option1 ...

positioning two out of three items in a navigation menu to the right and the remaining one to the left

I am looking to design a navigation bar that spans the full width of the screen, with the logo on the left side serving as a link back to the home page. Additionally, I want to include elements for register/login and cart. The background color should cove ...

Guide on implementing a date selector for each button/option clicked using Vue.js

My experience with Vuejs is still fresh, and I've incorporated 3 buttons named chart1, chart2, and chart3. Whenever any of these buttons are clicked, I want a Date selection to appear in a radio type format. You can see an example below: https://i.ss ...

Express and Passport encounter a Bad Request Error message

I've created a simple express API that utilizes passport.js for authentication: const express = require("express"); const app = express(); const LocalStrategy = require("passport-local").Strategy; const passport = require("passport"); passport.use( ...

Tips on boosting CSS specificity in Material-UI's makeStyle for styled components in order to successfully override the root style

As a newcomer in the world of React, I am attempting to utilize MUI makeStyles to customize the existing styles. However, I have encountered an issue where setting fontWeight to 'bold' does not seem to work, even when using !important. Any sugges ...

Font size transition on pseudo elements is not functioning properly in Internet Explorer when using the "em" unit

When I hover over, the font awesome icon and text on this transition increase in size. All browsers work well with this effect except for IE 11. This example demonstrates the same transition using px (class test1) and em (class test2). While using px wor ...

Troubleshooting "These dependencies were not found:" error message during deployment on Netlify, despite successful execution of yarn run serve on local machine

Currently, as I am creating a website using Vue.js, yarn, and Netlify. The build process works smoothly on my local machine when running yanr run build. However, upon deploying it through Netlify, an issue arises: 5:17:55 PM: failed during stage 'bui ...

Unable to modify the background image of the button

Currently, I am working on this element I am trying to insert a background image into the "Click" button, but I am not seeing any results. Here is the HTML and CSS I am using: .cn-button { position: absolute; top: 100%; left: 50%; z-ind ...

Thick labels in Chart.js are shortened with three dots

Is there a way to show the entire label without it getting truncated with 3 dots? I have experimented with different options from https://www.chartjs.org/docs/master/axes/index, including padding, but so far I haven't been successful. The full date da ...

Submitting an image from React and Redux to the backend: A comprehensive guide

I'm currently working with the MERN stack and facing an issue while trying to upload an image in the front end (react) and then access it in the backend (express, nodejs) for later storage. Despite using multer, I keep encountering 'undefined&apo ...

Prevent the hiding of a select element with jQuery Chosen Select

I am facing difficulty hiding a select element with the chosen-select class if it does not have any elements present. I attempted: $("#Category2").hide(); and also tried removing the chosen-select class before hiding the element: $("#Category2").re ...

Utilize the CSS content property to embed an image without causing it to distort in size

Struggling to swap out one image for another without stretching it? In my demo, I replaced an elephant with a lion using only CSS - no changes allowed to the HTML. Unfortunately, the lion image ends up stretched. Even adding background-size: cover doesn&ap ...

Creating a unique Voronoi Diagram wrap

I am currently working on the creation of a fantasy-style map that is procedurally generated using the cells of a Voronoi diagram to determine different terrains. While working on the tectonic plate generation, I came to the realization that having wrappi ...

CSS - What's the best way to create a dynamic resizing input box in web design?

How can I create an input box that automatically wraps text and shrinks to fit its size? What CSS property should I use for this? I attempted to use width: auto to scale it, but it didn't work as I expected. ...

Altering the text and functionality of buttons with jQuery

A JavaScript method I have is designed to change based on the state of a button, which is determined by using indexOf("..some text.."). $('#add1').click(function(){ if($(this).text().indexOf("Add Me!")) { $.ajax({ type: & ...

Progress bar carousel component based on advancement movements

Here is the mockup I am working with: https://i.sstatic.net/bIepQ.png So far, I have made good progress with this code: https://codesandbox.io/s/codepen-with-react-forked-16t6rv?file=/src/components/TrendingNFTs.js However, I am facing a couple of challe ...

Can you tell me what that sequence of characters is at the conclusion of a styled-component?

Technology Stack: React, Typescript I believe this question may have been asked before, but I am unsure how to search for it... I am interested in creating a wrapper for the styled-components library... Here is the API reference for the specific packag ...

Personalizing Web Push Alerts (Google Chrome)

I successfully implemented a web push notification for Google Chrome using Google Project and Service Worker. One thing I'm curious about is how to customize or style the push notification. The plain message box doesn't quite cut it for me – I ...