Expand the animation's size from the middle when hovering over it in Firefox

I am currently working on an animation where the size of my span element increases upon hover. However, I am facing an issue with Mozilla Firefox (50.1.0) as the animation does not begin from the center of the mouse cursor like it does in Safari and Google Chrome.

Why is this happening?

https://jsfiddle.net/9rrbzwem/11/

$(document).mousemove(function(e) {
  $("span").css({
    left: e.pageX - 50,
    top: e.pageY - 50
  });
});

$("div").hover(function() {
  $(this).stop().animate({ opacity: 0.5 }, 0);
  $("span").stop().animate({
    height: 100,
    width: 100,
    margin: 0 // changed
  }, 200);
}, function() {
  $(this).stop().animate({ opacity: 1 }, 0);
  $("span").stop().animate({
    height: 0,
    width: 0,
    margin: 50 // changed
  }, 200);
});

Answer №1

To position a span element using css transform, you can utilize the following code snippet.

$(document).mousemove(function(e) {
  $("span").css({
    left: e.pageX,
    top: e.pageY
  });
});

$("div").hover(function() {
  $(this).stop().animate({ opacity: 0.5 }, 0);

}, function() {
  $(this).stop().animate({ opacity: 1 }, 0);

});
div {
  width: 400px;
  height: 100px;
  background-color: grey;
  position: absolute;
}
div:hover span {
   width: 100px;
   height: 100px;
   -moz-transform-origin: center;
   -webkit-transform-origin: center;
   transform-origin: center;
}
span {
  display: block;
  height: 0px;
  width: 0px;
  position: absolute;
  background: red;
  border-radius: 50px;
  pointer-events: none;
  -moz-transition:  width 2s ease, height 2s ease;
  -moz-transform: translate(-50%, -50%);
  -moz-transform-origin: center;
  
  -webkit-transition:  width 2s ease, height 2s ease;
  -webkit-transform: translate(-50%, -50%);
  -webkit-transform-origin: center;
  
  transition: width 2s ease, height 2s ease;
  transform: translate(-50%, -50%);
  transform-origin: center;
}
<div><span></span></div>

https://jsfiddle.net/gt73k2ox/

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

JavaScript double-click functionality is not operational on IE9 and IE11 browsers

My JavaScript code has an issue where single-click opens a link in a new tab and double-click opens a lightbox. This works perfectly in all browsers except for IE9 and IE11. In my initial code, both single-click and double-click function correctly. However ...

What is causing this form to submit?

I need help with sending emails via AJAX. My problem is that the form keeps submitting and refreshing, even though I haven't used GET to send anything in the URL. HTML: <form onsubmit="ajaxEmail(); return false;" > <input type=" ...

What is the best way to set a parent element's width to be the same as one of

Is it possible to make the width of div.main match that of table.tbl2? In this scenario, I want inline4 to be on the second line and for the width of div.main to be identical to the width of table.tbl2. .container { text-align: center; } .main { di ...

Play around with my design

I'm having trouble with my styling and need some assistance. Specifically, I want to make sure that my page_content_div appears under my header instead of below the right and left carousel controls. I tried using float:left on the page_content_div, bu ...

Is it feasible to create a self-contained HTML document that can interact with client serial ports through JavaScript?

Is it feasible to execute a client-hosted HTML file (including scripts) that can interact with the computer's serial ports? I'm looking for a portable 'applet' that can be used to configure a device connected via serial communication u ...

Backdrop in Bootstrap Modal Does Not Fully Cover Buttons and Input Fields

Currently, I am working with mysql and php on a user.php page that caters to user interactions. The main content in the center <div> is dynamically updated through php whenever a link on the same page is clicked. To elaborate, when a user clicks on a ...

Only scroll the div if it is not within the visible window

I've been looking at this snippet: The sidebar division is what I'm focusing on right now. I want the div to scroll along as I scroll down the page, but I need it to stop scrolling when its bottom is in view. The same should apply when scrollin ...

Less-middleware in Node.js not automatically compiling files

I've incorporated the less-middleware into my Node.js Express app, but I'm encountering an issue. Whenever I update my screen.less file, it doesn't recompile automatically. To trigger a recompilation, I have to delete the generated .css file ...

The MongoDB regex is failing to provide the expected outcome

I'm facing an issue with searching data in MongoDB. I have a table with approximately 5000 entries of data that need to be searched based on multiple columns with specific priority criteria. The first priorities for the search are symbol, name, co_nam ...

What is the best way to conceal a button while maintaining its position in the layout?

My intention is to place two buttons, Reset Form and Save, next to each other using the following code. I want the Save button to be hidden when the user first lands on the page, but reveal itself as the user progresses through the forms. Even when the S ...

@media queries for min-width and max-width dimensions

My current setup uses @media queries: HTML: <head> <meta name="viewport" content="width=device-width, user-scalable=no" /> </head> CSS: @media screen and (min-width: 769px) { /* ADD STYLES HERE */ } @media screen and (min-devic ...

Is it possible to drag and drop images within a contenteditable element while they move between text and inner elements?

I have a contenteditable div with images and text, and I want to be able to drag the images around within the div while pushing the text out of the way. Any suggestions on how I can achieve this? Thank you! PS: I attempted using jquery-ui draggable/dropp ...

Generate 2 configurations for webpack

Currently, I am facing a challenge while building a webpack file. The issue arose when I needed to incorporate the 'node' target due to conflicts with an 'fs' function that reads certain files. Subsequently, I decided to split my config ...

How can I use one CSS child theme for three WordPress sites?

Currently, I am in the process of developing a website that spans three domains: en.mydomain.com ar.mydomain.com ur.mydomain.com All of these websites share the same theme but contain different content... I am looking to streamline the process by havin ...

Having trouble getting Tinymce to appear on the screen

I am currently attempting to install TinyMCE for use with my text editor in order to provide the user with a text box similar to the one on Stack Overflow. However, I am encountering an issue where it is not displaying as expected. In the header of my ind ...

Update the CSS dynamically using JavaScript or AngularJS

Is there a way to dynamically modify this CSS style using JavaScript or in an Angular framework? .ui-grid-row.ui-grid-row-selected > [ui-grid-row] > .ui-grid-cell{ background-color: transparent; color: #0a0; } .ui-grid-cell-focus ...

A guide on accessing React hook state within a Highcharts event listener

Struggling to update state within an event listener using React hooks and attempting to add to the existing state: import React, { useState } from 'react'; import { render } from 'react-dom'; import HighchartsReact from 'highchart ...

In IE8, CSS classes assigned to HTML5 elements are removed when they are printed

Currently, I am facing a challenge where I need to ensure proper printing functionality in IE8. The issue arises when using HTML5 features (such as sections) along with CSS on a page - the problem occurs specifically during printing. For example, when tryi ...

Call the javascript function (provided as a parameter) from native iOS code

I am grappling with a JavaScript function structured like this. function getState(){ return "Hello"; } var cryptico = (function() { var my = {}; my.generateRSAKey = function(passphrase, bitlength) { Math.seedrandom(sha256.hex(passphr ...

Trouble pausing CSS slide using -webkit-animation-play-state:paused; finding it ineffective

Below is the code snippet in question: .picTransition .item { position: absolute; left: 0; right: 0; opacity: 0; -webkit-animation: picTransition 56s linear infinite; -moz-animation: picTransition 56s linear infinite; -ms-animation: ...