Rendering Radial Gradients Using CSS3 in Google Chrome

While experimenting with animating radial gradients using jQuery, I came across an interesting observation (take a look at this JSFiddle). As I moved the mouse pointer over the left side of the element, the position animation appeared smooth. However, moving it to the far right resulted in a less smooth experience, with noticeable jumps in position if the mouse was moved slowly enough.

This inconsistency seems like some sort of rounding error, but the reason behind it remains unclear to me. Any thoughts or insights on why this might be happening? I've only tested it on Google Chrome so far, and the issue seems to occur only in the horizontal direction.

CSS

html { background: #fff; }
html, body {
    width: 100%;
    height: 100%;
}

body { background: #000; }

JavaScript

$('body').on('mousemove', function(event) {
    var x = event.pageX;
    var y = event.pageY;

    $(this).css('background', '-webkit-radial-gradient(' + x + 'px ' + y + 'px, transparent 10%, #000 5%)');
});

Can anyone else replicate this issue, or is it just affecting me?

EDIT: It seems to work fine in Safari.

Answer №1

Replicating the effect can be achieved by utilizing a ticker that relies on time intervals rather than solely relying on the mousemove event. As mentioned in this answer, the smoothness of the animation is improved by implementing this technique. I have enhanced your existing fiddle by incorporating the ticker from the linked thread. You can view the modified version here: http://jsfiddle.net/rh4Ljro4/

Below is the important javascript snippet:

var container = $('body');
var contWidth = container.width();

var intervalId;
var mouseX, mouseY;

//the ticker function is executed 60 times per second
function ticker(){
     $(container).css('background', '-webkit-radial-gradient(' + mouseX + 'px ' + mouseY + 'px, transparent 10%, #000 5%)');
}

//this interval calls the ticker function every 16 milliseconds
intervalId = setInterval(ticker, 16); //33 millisecond is about 30 fps while 16 would be roughly 60fps

container.mousemove(function(e){
    mouseX = e.offsetX; //store the current mouse position for reference during the interval
    mouseY = e.offsetY;
});

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

Develop a RESTful API in Node.js that allows for the sending of audio files along with JSON

My current project involves a REST API that I've built using node and express. I'm now facing a challenge where I need to send both JSON Data and an Audio File in a single http request. The audio file needs to be playable on the client side. JSO ...

The Bootstrap modal fails to retrieve and display fresh data from the database

I am facing a challenge in my index view where I display a list of records with an Edit button for users to modify certain details. When the Edit button is clicked, a bootstrap modal pops up allowing users to edit specific fields. After they click Save, th ...

Am I utilizing the htmlspecialchars function properly?

My main objective is to protect the user from malicious code and prevent XSS attacks. I have implemented a series of checks to filter the user's input before storing it in the database. The user input is stored in the $post variable. $post = htmlspec ...

Unable to transmit FormData from a JSP page to a Servlet through jquery-AJAX

Having trouble sending POST data from a JSP file to a servlet using jQuery-AJAX. The servlet is receiving null values in the post request. Although the console on the JSP page displays the correct data, and Firebug in Mozilla confirms that the data is bei ...

Experiencing 429 Too Many Requests error on Angular 7 while attempting to perform multiple file uploads

Whenever I attempt to upload a large number of files simultaneously, I encounter an issue. The API interface only allows for the submission of one file at a time, requiring me to call the service for each individual file. Currently, my code looks like thi ...

Unexpected Placement of Bootstrap 4 Table Spinner in Chrome and Internet Explorer

I am struggling to create a dynamic spinner within a table's tbody using Bootstrap 4. Here is what I have attempted so far: HTML <div class="container mt-2"> <div class="card"> <div class="card-body"> <div class="row"> ...

issues with conditional statement

I'm encountering an issue with the if statement not functioning as expected, and I can't seem to figure out why. The if condition always gets displayed regardless of the input. To troubleshoot, I initially used a temporary code snippet for the co ...

How can I troubleshoot an image not appearing in Bootstrap within a Laravel Blade file while using PHPStorm?

Forgive me if this sounds like a silly question: I attempted to use the following src attribute in an img tag to show an image on a website created with Bootstrap, while using phpstorm with a laravel blade file: src="C:\Users\MAHE\Pictures&b ...

Is the same-origin policy being breached?

Hello there, I've been encountering an issue with my jQuery AJAX Call to retrieve data from a self-hosted webservice on the same domain. The response always returns as 0, indicating a cross-domain problem, even though it shouldn't be occurring. ...

Exploring ways to capture all console outputs or retrieve the current console content in frontend development

Currently working with Angular and looking to integrate a bug reporting feature into my application. I want to capture the content of the browser's console for debugging purposes. However, I'm unsure of how to access it. Not all errors are logge ...

Rendering data in React using asynchronous JavaScript and XML (

I'm facing difficulties rendering my components with ajax data. I am unsure how to include a component inside my render method along with the ajax data. Below is my AccountPage.js code: import Close from '../../icons/Close' import Delete ...

Change to a different button based on a condition in ReactJS

Currently, I am tackling a ReactJS project that involves the utilization of the following function: function checkMoves() { let index = 0; let moveList = []; while (index < props.moves.length) { if (!moveList.includes ...

Creating a centered horizontal line in a table cell using CSS

element, imagine placing a line in the middle of a table cell (td) like this: To achieve this effect, you can insert a line within the td as shown in the image below: https://i.sstatic.net/Gn8tE.png This allows you to write text while keeping the line v ...

What is the process of submitting a form using ajax .done() method after preventing the default event?

While validating my form with ajax, I am specifically checking if the username and password entered are correct. If they match, the form should be submitted and redirected to the welcome page; otherwise, an error message should be displayed. Although ever ...

I am having trouble setting the z-index for the navigation component in Tailwind CSS and Next.js

Currently, I am immersed in a Next.js project that utilizes Tailwind.css. Within this project, there is a header component known as nav, styled as follows: <div className="sticky top-0 z-100 body bg-white flex flex-row items-center">Nav con ...

Show information upon opening

I am currently working on a project that involves 4 different divs, and I need the content of each div to be displayed based on dropdown selection. I found a code snippet that was close to what I needed, but after trying to adjust it, I haven't been a ...

Rotation of objects using Three.js on a spherical surface

I have successfully implemented a particle system to evenly distribute points on a sphere and then place instances of a given geometry on those points. Now, I am looking to rotate those geometries to match the surface angle of the sphere. Below is the cur ...

Tips for transforming intricate JavaScript arrays into a unified array and iterating through to create a table

I need help combining two arrays that contain objects and reassigning the values in a standard format. Can anyone provide some guidance? Thank you. Here is my current situation: array1 = [{Apple: Ken, Orange: Mary, Melon: Tina, Strawberry: Jessica, Mango ...

Calculating the vertical distance between an element and the top of the page

I am attempting to calculate the distance between the top of an element and the top of the page every time the user scrolls. Although I have managed to make it work, the issue arises when scrolling - the distance remains unchanged. I tried addressing this ...

What is the proper way to activate speech recognition on electron?

I have a chatbot application running on Electron, and I am in need of implementing speech-to-text functionality. I initially tried using window.SpeechRecognition and window.webkitSpeechRecognition, but it seems like Chrome does not support speech recogniti ...