Issues with Custom Cursor Getting Trapped in the Upper Left Corner

I’m having trouble creating a custom cursor with blend mode exclusion. I've tried a few methods, but for some reason, when I added a cursor with blend modes, it only appears in the top left corner of my page and doesn't move. I want it to be the main cursor, but I’m not sure how to resolve this issue.

For reference, you can find the Codepen link here: https://codepen.io/ryanforprez/pen/vYyEWyL

    .cursor {
   position: fixed;
   width: 20px;
   height: 20px;
   border-radius: 50%;
   background-color: #ffff;

   mix-blend-mode: difference;
   z-index: 999;

  transition: transform 0.2s;
 }

 html,
 * {
 cursor: none;
pointer-events: none;

 }



<html>
<body onclick='window.location.href="work.html"'>
    
     </body>
 </html>

  <body>

    <div class="nav">

     <div class="name"><a href="work.html">Ryan Stewart</a></div>
<div class="info"><a href="information.html">Information</a></div>

</div>

        <div class="contact">   <a href="work.html">Click anywhere to enter.</a>
</div>



<marquee width="100%" direction="left" scrollamount="15" behavior="scroll">Ryan Stewart: Graphic Design, Art Direction, Letterform Design</marquee>
  <script>$(document).ready(function() {
  $(".hamburger-menu-button").click(function() {
  $(".main-box").toggleClass("main-box-clicked");
  $(".hamburger-box").toggleClass("hamburger-box-clicked");
  });

  var cursor = $(".cursor");

  $(window).mousemove(function(e) {
  cursor.css({
  top: e.clientY - cursor.height() / 2,
  left: e.clientX - cursor.width() / 2
  });
  });

  $(window)
  .mouseleave(function() {
  cursor.css({
    opacity: "0"
  });
  })
 .mouseenter(function() {
  cursor.css({
    opacity: "1"
  });
 });

 $(".link")
.mouseenter(function() {
  cursor.css({
    transform: "scale(3.2)"
  });
})
.mouseleave(function() {
  cursor.css({
    transform: "scale(1)"
  });
});

 $(window)
.mousedown(function() {
  cursor.css({
    transform: "scale(.2)"
  });
})
.mouseup(function() {
  cursor.css({
    transform: "scale(1)"
  });
});
 });</script>

Answer №1

I believe the issue lies in the presence of multiple opening and closing body and html tags in your code, creating chaos. Here is a cleaned-up and properly formatted version that should work smoothly:

$(document).ready(function() {
      $(".hamburger-menu-button").click(function() {
      $(".main-box").toggleClass("main-box-clicked");
      $(".hamburger-box").toggleClass("hamburger-box-clicked");
      });

      var cursor = $(".cursor");

      $(window).mousemove(function(e) {
      cursor.css({
      top: e.clientY - cursor.height() / 2,
      left: e.clientX - cursor.width() / 2
      });
      });

      $(window)
      .mouseleave(function() {
      cursor.css({
        opacity: "0"
      });
      })
     .mouseenter(function() {
      cursor.css({
        opacity: "1"
      });
     });

     $(".link")
    .mouseenter(function() {
      cursor.css({
        transform: "scale(3.2)"
      });
    })
    .mouseleave(function() {
      cursor.css({
        transform: "scale(1)"
      });
    });

     $(window)
    .mousedown(function() {
      cursor.css({
        transform: "scale(.2)"
      });
    })
    .mouseup(function() {
      cursor.css({
        transform: "scale(1)"
      });
    });
     });
.cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #cccc;

    mix-blend-mode: difference;
    z-index: 999;
    transition: transform 0.2s;
}

* {
    cursor: none;
    pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="nav">
    <div class="name">
        <a href="work.html">Ryan Stewart</a>
    </div>
    <div class="info">
        <a href="information.html">Information</a>
    </div>

</div>
<div class="contact">
    <a href="work.html">Click anywhere to enter.</a>
</div>
<marquee width="100%" direction="left" scrollamount="15" behavior="scroll">Ryan Stewart: Graphic Design, Art Direction, Letterform Design</marquee>
<div class="cursor"></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

There seems to be an issue with the functionality of the Bootstrap Modal

I've been working on incorporating bootstrap login Modal functionality into my code, but for some reason, the screen is not displaying it. Here's what shows up on the screen: https://i.sstatic.net/UIU2w.png The red box in the image indicates whe ...

"What might be causing the error 'cannot access property 'top' of undefined' while trying to read

My website has a sticky navbar fixed at the top, and this is the structure of my sticky navbar: $(function() { $(window).scroll(function() { if ($(window).scrollTop() > $(".b").offset().top + $(".b").height() && $("input").val() == "") { ...

Is it possible for me to retrieve/load a <datalist> element from a different file?

I'm in the process of developing a Google Chrome extension that essentially consists of a dropdown menu and an input box with datalists. The user can change their selection in the dropdown menu, which will then switch the datalist being used by the in ...

Tips on how to patiently wait until the database connection is established and all queries are successfully executed for every database specified in an array

A file containing JSON data with database details needs to execute a series of queries for each database connection. The map function is currently waiting for the database connection. Below is the start function function start() { console.log('func ...

Is the presence of hidden list items leading to excessive white space?

I have a menu that appears when hovering over a list item. Here is an example: <li> <ul class="topmenu"> <li class="submenu"> <a class="otherIT" href="#" title="Common IT Tasks"><img src="./images/ittasks.png" alt= ...

Enhancing the appearance of input range sliders using before and after elements for custom styling

I'm looking to create something similar to the image linked below https://i.sstatic.net/Czef9.png Note:: The above image features a V-shaped icon, which is what I'm aiming for. Currently, I am utilizing input[type="range"]. The foll ...

Set dimensions for the input submit border inside

Can anyone help me figure out how to prevent the border from being drawn inside of my submit button element? I have a specific width and height set for cross-browser consistency, but in Firefox 15 and IE7 the border gets applied to the inside of the elemen ...

What could be causing this JSON variable to be undefined?

Check out the code snippet below. JavaScript <script> function saveUserInfo() { var userInfo = $('span input').serialize; alert(userInfo.username); } </script> HTML <span> User name : <input type="text" name="us ...

Vue - the <script setup> element is unable to execute scripts

I have a functional widget from Atlassian that works as expected when used in an HTML file: <html lang="en"> <head> <script data-jsd-embedded data-key=<key> data-base-url=https://jsd-widget.atlassian.com src=https://jsd-w ...

Node.js encounters issues when attempting to rename a folder

I am facing an issue while attempting to rename a folder within a WordPress theme after performing search-replace operations using a node script. The renaming process for the folder seems to be unsuccessful. My objective is to change this public_html/wp- ...

What is the best way to achieve a stylish Bootstrap modal design with a blurred and transparent header, as well as a left sidebar that seamlessly blends into

Is it feasible to create a modal with a blurred (transparent) background for the header section, allowing the site to show through? Additionally, can a sidebar on the left side of the modal also be transparent and blurred, revealing the site underneath? C ...

Jest's expect.any(Object) function is not able to match CancelToken

After converting some files in a project to TypeScript, I encountered a test failure related to the following code: expect(mocks.request).toHaveBeenCalledWith({ headers: { 'Content-Type': 'bar' }, method: 'put', params: ...

Removing an item from an array while also updating one of its attributes in JavaScript

I am facing a challenge with this list of objects: const flights = [ { id: 00, to: "New York", from: "Barcelona", cost: 700, scale: false }, { id: 01, to: "Los Angeles", from: "Madrid", cost: 1100, scale: tru ...

Directive not working on Mozilla Firefox

Currently, I have a directive set up to display an image as a background image. This works perfectly fine in Chrome and Safari, but for some reason, it doesn't seem to be functioning properly in Firefox as the background images are not showing up. Aft ...

A guide on utilizing the index column for multiple tables using just one statement in the datatable js library

I've incorporated the datatable js for managing two tables on a single page. HTML <!-- Table#1 --> <table class="dataTable"> <thead> <tr> <td>#</td> <td>col1</td> </tr> &l ...

Executing javascript function after the successful completion of 4-5 Ajax requests

My task involves conducting 4-5 Ajax calls and only when all of them are successful, I need to trigger a JavaScript function. Currently, I am using ExtJS for this purpose, although I could also achieve the same with JQuery. What is the best approach to ca ...

The instantiation of the cloudinary module failed because of an error with the injector

I am currently developing a MEAN application based on the template provided by Linnovate. You can find the template at https://github.com/linnovate/mean My goal is to integrate a module called Cloudinary into my application. To achieve this, I followed th ...

In order to preserve the data inputted by the user within a file

Check out this HTML code snippet:- ` AngularJS | $http server <div ng-controller="people"> <ul> <h2> Names and Ages of programmers: </h2> <li ng-repeat="person in persons"> { ...

Unable to reference a file in a local directory using href in HTML

I'm attempting to create a hyperlink to a local pdf file. I have discovered that using an absolute path will open the pdf in a new tab on my site. However, when I try to use a relative path, the console shows a warning "No match found for location wit ...

Trouble navigating cursor position on ngModelChange in Angular/Typescript

I'm currently facing an issue with my HTML input field combined with a typescript component utilizing ngModelChange. I am aiming to have the flexibility to edit the input value wherever necessary. Let's consider this scenario: The original inpu ...