Arranging circles on top of each other creates a dark line along the edges with rounded

I find myself entangled in quite the enigmatic venture.

My latest project involves crafting a mouse that doubles as a 'torch / searchlight'. Whenever there is a hover action on any text (inline elements, buttons, and so forth), its color transitions from the standard white to black, set against a background with yellow undertones.

At present, my setup includes:

const _$shadow = $('.b-cursor__shadow');
const _$front = $('.b-cursor__front');
const _$back = $('.b-cursor__back');

$(document).on('mousemove', (e) => {
  _$back.css({
    left: e.pageX,
    top: e.pageY
  });
  _$front.css({
    left: e.pageX,
    top: e.pageY
  });
  _$shadow.css({
    left: e.pageX,
    top: e.pageY
  });
});
html,
body {
  padding: 0;
  margin: 0;
  cursor: none;
  background: red;
}

.test {
  background: darkblue;
}

p {
  color: white;
  font-family: sans-serif;
  font-size: 20px;
  max-width: 30rem;
  padding: 1rem;
  margin: 1rem;
  border: 1px solid white;
}

p,
span,
a {
  position: relative;
  z-index: 105;
}

.b-cursor__back,
.b-cursor__front,
.b-cursor__shadow {
  position: fixed;
  width: 8rem;
  height: 8rem;
  margin-left: -4rem;
  margin-top: -4rem;
  border-radius: 50%;
}

.b-cursor__shadow {
  box-shadow: 0px 0px 10px 10px rgba(231, 232, 192, 1);
}

/* background changes */
.b-cursor__back {
  z-index: 104;
  background: #18173e;
  clip-path: circle(50% at 50% 50%);
}

.b-cursor__front {
  z-index: 106;
  background: white;
  clip-path: circle(50% at 50% 50%);
  mix-blend-mode: difference;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pretium pharetra ipsum, at placerat ante maximus vitae. Duis lacus urna, posuere id dapibus in, semper vitae massa. Quisque at egestas nisl. In ex elit, imperdiet eu interdum a, auctor vitae ante. Pellentesque efficitur imperdiet elementum. Integer at nibh gravida nisl sodales ornare ut quis est. Suspendisse sem odio, congue vitae felis at, tincidunt interdum purus. Morbi vitae efficitur est, non congue ante. Proin vel odio et metus sodales lobortis quis ut justo. Phasellus rhoncus eu urna vitae tristique. Suspendisse potenti. Curabitur quis quam lobortis mi laoreet lacinia. Cras non ultrices eros. Nam sed leo et tortor vestibulum cursus nec eu massa. Suspendisse potenti.</p>

<section class="b-cursor">
  <div class="b-cursor__shadow"></div>
  <div class="b-cursor__back"></div>
  <div class="b-cursor__front"></div>
</section>
<div class="test">
  <p>Perhaps this will not work after all
    <p>
</div>

(source link)

The current configuration almost achieves the desired outcome, but encounters pixel troubles due to the border-radius: 50% not handling stacking divs correctly. A visual representation can be found in the image below:

https://example.com/image.png

Query: How can I eliminate the black border formed by overlapping two equally sized elements while maintaining the existing text effect?

Answer №1

One approach to enhance the code is by adding a pseudo-element above to conceal the small border. The code can be simplified further by shifting the container instead of each element individually. Additionally, the use of clip-path may not be necessary.


const _$cursor = $('.b-cursor');

$(document).on('mousemove', (e) => {
  _$cursor.css({
    left: e.pageX,
    top: e.pageY
  });
});

Lorem ipsum dolor sit amet...

Another approach using pure JS without jQuery:


document.onmousemove = function(e) {
  document.body.style.setProperty('--mx',(e.pageX)+'px');
  document.body.style.setProperty('--my',(e.pageY)+'px');
  
  document.body.style.setProperty('--x',(e.clientX)+'px');
  document.body.style.setProperty('--y',(e.clientY)+'px');
  

}

Optimization can still be done with an additional gradient that replaces the shadow and border:


document.onmousemove = function(e) {
  document.body.style.setProperty('--mx',(e.pageX)+'px');
  document.body.style.setProperty('--my',(e.pageY)+'px');
  
  document.body.style.setProperty('--x',(e.clientX)+'px');
  document.body.style.setProperty('--y',(e.clientY)+'px');
  

}

A different alternative for browsers like Safari:


document.onmousemove = function(e) {
  document.body.style.setProperty('--mx',(e.pageX)+'px');
  document.body.style.setProperty('--my',(e.pageY)+'px');
  
  document.body.style.setProperty('--x',(e.clientX)+'px');
  document.body.style.setProperty('--y',(e.clientY)+'px');
  
}

Answer №2

This solution could potentially meet your requirements.

const _$shadow = $('.b-cursor__shadow');
const _$front = $('.b-cursor__front');
const _$back = $('.b-cursor__back');

$(document).on('mousemove', (e) => {
  _$back.css({
    left: e.pageX,
    top: e.pageY
  });
  _$front.css({
    left: e.pageX,
    top: e.pageY
  });
  _$shadow.css({
    left: e.pageX,
    top: e.pageY
  });
});
html, body {
    padding: 0;
    margin: 0;
    cursor: none;
    background: red;
}
.test {
    background: darkblue;
}
p {
    color: white;
    font-family: sans-serif;
    font-size: 20px;
    max-width: 30rem;
    padding: 1rem;
    margin: 1rem;
    border: 1px solid white;
}
p, span, a {
    position: relative;
    z-index: 105;
}
.b-cursor__shadow2, .b-cursor__back, .b-cursor__front, .b-cursor__shadow {
    position: fixed;
    width: 8rem;
    height: 8rem;
    margin-left: -4rem;
    margin-top: -4rem;
    border-radius: 50%;
}
.b-cursor__shadow {
    box-shadow: 0px 0px 10px 20px rgba(231, 232, 192, 1);
    z-index: 107;
    height: 8rem;
    width: 8rem;
}
.b-cursor__shadow2 {
    background: radial-gradient(circle at center, #18173e 100%, #18173e 25%);
    z-index: 109;
    height: 8rem;
    width: 8rem;
    background-color: transparent;
}
/* additional styles for cursor */
.b-cursor__back {
    z-index: 104;
    height: 8rem;
    width: 8rem;
    background: radial-gradient(circle at center, #18173e 100%, #18173e 25%);
    background-size: 100% 100%;
    background-position: 50% 50%;
}
.b-cursor__back:after {
    width: 7rem;
    height: 7rem;
    content: '';
    border-radius: 50%;
    background: transparent;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0px 0px 0px 1rem #18173e;
    transition: all 0.3s linear;
    mix-blend-mode: normal;
}
.b-cursor__front {
    z-index: 106;
    height: 8rem;
    width: 8rem;
    background: white;
    background: radial-gradient(circle at center, #ffffff 100%, #ffffff 25%);
    background-position: 50% 50%;
    mix-blend-mode: difference;
}
.b-cursor__front:after {
    width: 7rem;
    height: 7rem;
    content: '';
    border-radius: 50%;
    background: transparent;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0px 0px 0px 1rem #ffffff;
    transition: all 0.3s linear;
    mix-blend-mode: normal;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis pretium pharetra ipsum, at placerat ante maximus vitae. Duis lacus urna, posuere id dapibus in, semper vitae massa. Quisque at egestas nisl. In ex elit, imperdiet eu interdum a, auctor vitae
  ante. Pellentesque efficitur imperdiet elementum. Integer at nibh gravida nisl sodales ornare ut quis est. Suspendisse sem odio, congue vitae felis at, tincidunt interdum purus. Morbi vitae efficitur est, non congue ante. Proin vel odio et metus sodales
  lobortis quis ut justo. Phasellus rhoncus eu urna vitae tristique. Suspendisse potenti. Curabitur quis quam lobortis mi laoreet lacinia. Cras non ultrices eros. Nam sed leo et tortor vestibulum cursus nec eu massa. Suspendisse potenti.</p>

<section class="b-cursor">
  <div class="b-cursor__shadow"></div>
  <div class="b-cursor__back"></div>
  <div class="b-cursor__front"></div>
  <div class="cursor_now"></div>
</section>
<div class="test">
  <p>ja uh misschien werkt dit wel niet
    <p>
</div>

Answer №3

experiment with inserting

filter:blur(1.2px); /* you can also try values ranging from 0.5px to 1.7px */

within the outer ring or inner rings in your stylesheet

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

CSS- Strategically placing and centering images above specific keywords in (any) HTML content without disrupting the flow of text

My main objective involves dynamically inserting images above text on any given page using a content script. The challenge lies in maintaining the proper alignment of the text after adding the images. To achieve this, I surround the words where the image i ...

What are the steps for transforming an HTML page into a fully-fledged Vue or React project?

I have been customizing a dashboard using AdminLTE 3, removing unnecessary parts and modifying the HTML and CSS files. However, I now need to convert this project into either a Vue or React project. Currently, all I require is an index.html file with a bla ...

div-based fixed-header table

My current project involves creating a table using only div elements, with the added challenge of having a fixed header so it remains visible while scrolling. The initial setup was looking good until I attempted to implement the fixed header: Check out th ...

Move the DIV element to a static section within the DOM

In my Vue app, I have implemented methods to dynamically move a DIV called 'toolbox' to different sections of the DOM. Currently, the DIV is positioned on the bottom right of the screen and remains static even when scrolling. My goal is to use t ...

What are some effective methods for organizing HTML in a clean and orderly manner?

I have limited experience with HTML, but I need to layout a form in a precise manner similar to WinForms. Here is my attempt using the little CSS and HTML knowledge I possess: The issue lies in everything inside the white area being ABSOLUTELY LAID OUT .. ...

Using a repeating background in CSS with overflow displayed at the top rather than the bottom

Does anyone know how to make the repeating background 'start' fixed at the bottom of the div and overflow on the top? I want it to be the opposite of the default behavior. Let me illustrate what I'm trying to achieve with a small example. I ...

What is the best way to program a button to respond based on a specific selection?

I am working on a Django Python project that includes a list of numbers and a search button on the main page. My goal is to have the button redirect me to another page based on the number selected from the list. Here's what I added in my urls.py: url ...

Fade in and fade out elements with jQuery using opacity in Internet Explorer

I have encountered an unusual issue in Internet Explorer involving a CSS Overlay used for a lightbox. The problem arises when I apply the fadein and fadeout effects using jQuery - everything seems to work smoothly except in IE. Instead of displaying a smo ...

Adjust the element colors within a Vue loop with dynamic changes

Hey there! I'm currently working on achieving a unique design inspiration that involves colorful badges grouped together. Here's a visual reference: https://i.sstatic.net/5LDBh.png In the image, you can see these badges grouped in pairs, but the ...

Excess padding and margin issues in Bootstrap version 3.3

Currently, I am utilizing Bootstrap 3.3 to create a straightforward layout, following this structure: For the body and html elements: html,body{ background: #fff; height: 100%; width: 100%; padding: 0; margin: 0; } Additionally, on e ...

Prevent the page from scrolling while the lightbox is open

I am struggling with a lightbox that contains a form. Everything is functioning properly, but I need to find a way to prevent the HTML page from scrolling when the lightbox is active. <a href = "javascript:void(0)" onclick=" document.getElementById(& ...

Utilizing jQuery animation, generate a zoomOut effect on a square-shaped image that adjusts to fit the width or height of the window while preserving its

Right off the bat: using scale() is not a viable option. Is there a way to dynamically animate my image, which has been scaled to 700% in width or height, back to its original CSS dimensions of auto width and height? Below are the actual dimensions of my ...

Changing the properties of the admin bar when it is hovered over in

After successfully styling a button on the admin bar, I noticed a few imperfections in the implementation. The button in question is situated on the admin bar and is labeled "maintenance". Upon clicking the button, jQuery triggers the addition of the clas ...

Steps to conceal an accordion upon loading the page and reveal it only when clicking on a specific element

Below is the code I am using to display an accordion in a Fancybox popup. However, I do not want the accordion to be visible on page load. If I hide it, the content inside also gets hidden when showing the accordion in the popup. When user clicks on Click ...

Managing numerous range sliders in a Django form

My Request: I am looking to have multiple Range sliders (the number will change based on user selections) on a single page. When the sliders are moved, I want the value to be updated and displayed in a span element, as well as updating the model. The Issu ...

Troubleshooting problems with Flask's render_template()

I've been working on a Flask web application that requires users to be logged in to access the contents and functionalities. However, I've encountered an issue where, sometimes after logging in, instead of loading the full home page, a blank "abo ...

Creating a zebra-striped list using CSS can be done by styling even and odd list items differently

I am facing an issue with Angularjs and the table tag when using group loops. The problem arises in achieving correct zebra striping for the list. How can I solve this to ensure the zebra pattern is applied correctly? <table> <tbody> <tr ...

Creating an HTML table layout: A step-by-step guide

I am in need of assistance with designing an HTML layout. My goal is to display 3 columns for each table row as described below: Column #1 will contain text only. Column #2 will have an inner table, which may consist of 1 or 2 rows depending on the cont ...

Generating multiple div elements within an AJAX iteration

Currently, I am retrieving data from the server side using AJAX. My goal is to populate data from a list of objects into divs but I am facing an issue where I cannot create the div while inside the foreach loop. $(document).ready(function () { var ...

"Comparison: Utilizing HTML5 Video Player with IE8 Embed Fallback versus Implementing Fixed

This dilemma has me at my wit's end. In an HTML5 Video element, I've included an mp4, ogg, and an embedded mp4 fallback. However, on the embed fallback in IE8, all my attempts to position the fixed element (#fixed) above it with z-indexing have f ...