Grow an element starting from its center without being limited by the boundaries of a div

I'm faced with a puzzling issue that I believe has a simple solution, but it seems to be eluding me at the moment. Essentially, I have a div containing an image as its background. Upon clicking this div, I want another circular div (created using border-radius) to expand from the center of the first div and grow past its boundaries, effectively covering it in a circle shape. While I can make the circle expand without any trouble, it appears to be stuck within the confines of the initial div's top and left edges due to how it is centered.

Below is the animation code:

$(".projectContainer").click(function(){
  $(".circle").animate({
        width:'+=600px',
        height:'+=600px'},600);
});

The HTML structure:

<div class="projectContainer" id="A Head In The Box">
    <div class="circleContCont"><div class="circleCont">
            <div class="circle"></div>
    </div></div>
</div>

And here are the CSS styles for the elements involved:

.projectContainer {
   width:384px;
   height:288px;
   max-width:100%;
   background-color:#FFF;
   background-position: center center;
   display:inline-block;
   margin:7px;
   overflow:hidden;
}
.circleContCont {
   display:table;
   height:100%;
   width:100%;
   vertical-align:middle;
}

.circleCont {
   overflow:hidden;
   display:table-cell;
   vertical-align:middle;
}

.circle {
   width:0px;
   height:0px;
   margin-left: auto; 
   margin-right: auto;
   background: #FFF;
   border-radius: 50%;
   z-index:2;
}

The centering method used is based on a technique found here, which appears to be somewhat convoluted. There could possibly be a simpler approach to achieve the same result.

Edit: By changing the circle's position to absolute and animating the top and left values (-=300px), the circle can now extend beyond the parent div. However, maintaining central alignment remains a challenge. A video demonstration of how it was functioning before can be viewed here, while its current behavior is shown in this video.

Answer №1

Arrange your circle in a fixed position and then apply the code below for an animated effect

$(".projectContainer").click(function(){
  $(".circle").animate({
      width:'+=600px',
      left:'-=300px',
      top: '-=300px',
      height:'+=600px'
   },600);
});

Give it a try, click on the circle

$(".circle").click(function() {
  $(".circle").animate({
    'width': '+=600px',
    'left': '-=300px',
    'top': '-=300px',
    'height': '+=600px'
  }, 600);
});
.circle {
  height: 100px;
  width: 100px;
  background-color: black;
  position: absolute;
  left: 100px;
  top: 100px;
  border-radius: 1000px;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="circle"></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

Adjust the HTML code using jQuery and display it in a textbox

I have a piece of HTML code: <ul> <li class="1"><a>Option #1</a></li> <li class="2"><a>Option #2</a></li> </ul> <textarea>Display the updated HTML code here</textarea> The ...

Issue with Angular9-MatDatePicker: Unable to establish a connection with 'ngModel' as it is not recognized as a valid attribute of 'input'

Despite my efforts to implement ngmodel binding with matdatepicker, I am still encountering issues, even after reviewing multiple other posts on the topic. Here is a snippet of my HTML: <mat-form-field> <mat-label>Start Date</mat-label ...

Send an ArrayList to jQuery Flot

Good day. Apologies for any language barriers as English is not my first language. I am a novice in [see tags] and I have a web application that gathers a date and a serial number to execute a SQL query. The query returns some data (measurement values an ...

Tips for storing jQuery ajax response in React's cache

While many people are concerned with disabling jQuery ajax cache in React, my question is a bit different. I actually want to enable caching, or more specifically, store the data retrieved from the initial ajax call in browser memory so that the REST api w ...

Calculate the combined total of two inputted values instantly

Is there a way to add two separate numerical inputs together in real-time and display the sum in a third variable? Here's a clearer explanation: First Variable: 100 (input) Second Variable: 150 (input) Sum: 250 (calculated, not input) Any suggesti ...

Errors may occur when attempting to auto-refresh a page with a PHP-generated image using Ajax

When I include the image somepage.php in my code, it displays correctly. However, if I use Ajax to refresh the div containing somepage.php, the text becomes distorted. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

Choosing an option in react-select causes the page to unexpectedly shift

Encountering a problem with a mobile modal developed using react-select. The selectors are within a div with fixed height and overflow-y: scroll. Upon selecting an option for the 'Choose observer' select, the entire modal briefly jumps down in th ...

Angular app encounters issue with Firebase definition post Firebase migration

Hey there, I'm currently facing an issue while trying to fetch data from my Firebase database using Angular. The error message 'firebase is not defined' keeps appearing. var config = { databaseURL: 'https://console.firebase.google. ...

Fetching data from MySQL using Ajax technology

I need assistance with my form that is supposed to input a name and phone number, fetch data from a MySQL database based on the input values, and display the results. However, when I execute the query using an onclick function, instead of retrieving data f ...

Access Information within live tabs

When attempting to click on any tabs in order to retrieve their respective data, I am successfully able to do so. However, I'm only able to retrieve the data of one row at a time. Can anyone provide assistance with this issue? <div class="col-lg-1 ...

Handling Cross-Domain Issues with jQuery Ajax and PHP MySQL - Troubleshooting Internal Server Error 500

Currently, I'm using a jQuery ajax call to update my database by utilizing a php script. This is the specific call that I execute: $.ajax({ url: "update.php", type: 'POST', dataType: 'jsonp', data: ...

Is it possible to insert both the name and value of a complete attribute within an element using a string in Razor?

There is a common way to achieve this in asp.net MVC Razor Engine: @{ string myValue = "foo" } <h1 hello='@myValue'></h1> However, I am interested in an alternative approach that might result in an error: @{ string myAttri ...

What is the best way to design a dynamic menu using HTML, CSS, and jQuery, where each li element gradually disappears?

Consider this menu structure: <ul class="main-menu"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> My task is to dynamically hide th ...

Include a parent class within the style tags in your CSS code

Currently, I am facing an issue with a web application that I am developing. On the left side of the page, there is an editable area, and on the right side, there is a live preview. The live preview area contains an HTML file with specific fields that can ...

Testing the local transmission of form data via Javascript: A Step-by-Step guide

Currently studying how to send forms using JavaScript by manually creating an XMLHttpRequest. Towards the end of the provided example, there's a note: Note: If you want to send data to a third party website, keep in mind that this use of XMLHttpRequ ...

Activate the counter as soon as the error message appears

To effectively track the number of errors generated upon form submission, I require a counter mechanism. The errors are identified by the CSS class .validmissing. For instance, if a user encounters 5 errors upon submitting the form, the counter should be ...

Mastering the Art of Tab Selection with Jquery

I am trying to implement a tabs control using jQuery. Here is the HTML code I have: <div id="tabs" class="news1"> <ul> <li><a href="#tabs-1">Track</a></li> <li><a href="#tabs-2">History&l ...

Accessing a specific segment of HTML using Java

Attempting to navigate through a bunch of HTML, I'm aiming to isolate specific sections. I'm specifically looking to retrieve 'THISISTHEBITIWANT' from the following HTML code. <li class="aClass"> <a href="example/THISISTHEB ...

What is the best method for designing a filtering menu with a "Narrow By" option?

Looking to create a sidebar menu similar to the functionality on mcmaster.com. This specific feature allows users to efficiently filter products and toggle through different options dynamically. Upon selecting the "metric" option, the entire page adjusts t ...

Steps for populating a datatable from a JSON object with keys and values as columns

Typically, when populating a JQuery datatable, we provide a Json Array containing json objects and map each field to a column. However, I have a single json object and I want to display each key in one column and its corresponding value in the next column ...