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

When I access the website through the LinkedIn app, my CSS styles are getting jumbled up

Is there a way to resolve the problem I'm facing with CSS when accessing the site through the LinkedIn app on iPhone? The issues don't occur on Android. If anyone has a solution, please share. Thank you :) Click Here ...

How can the cross-domain AJAX form submission be achieved?

I am currently utilizing jQuery along with the jQuery form plugin Within the jQuery form plugin, there is a method called ajaxSubmit. This method allows you to submit a form via ajax and receive a response. I find it intriguing how this process works even ...

Unable to access the accurate value of a variable beyond the scope of the getJSON function

There is a variable named items in my code. When I access its value inside the getJSON function, I receive the correct value. However, when I try to access its value outside of the getJSON function, I only get an empty string. Can someone help me underst ...

The issue of Ajax failing to execute an HTTP POST request in an HTML environment

I am creating a sample HTML code that involves making HTTP post requests using an Ajax function. The task at hand is to execute 2 HTTP POST requests and 1 GET request sequentially based on the correct response received. POST: URL: http://localhost:8082 ...

"Enhance your viewing experience with VideoJS fullscreen mode and F

While attempting to open an HTML5 video using VideoJS in Fancybox, everything is running smoothly except for one small issue: the fancybox close button is appearing above the video content. When trying to adjust the z-index to a lower value, the close but ...

What is the best way to ensure that a link fragment scrolls to the top of the page in Angular?

Having trouble with link fragments in my Angular single-page-app: <a href="/#/search">Search</a> When clicking this link, it takes me to the right page but keeps my scroll position. I want it to scroll to the top of the page so I'm curre ...

Parenting and Child Components: Keeping the State in Sync

I am currently diving into my initial React project which focuses on a basic expense tracker for credit cards. While I'm still in the learning phase, I hope you can decipher the intent behind my code. My current roadblock involves mapping the state an ...

What is the best way to align the bottom of an anchor element with the bottom of an SVG element when positioning them together

I am working on a test website where I am trying to create an interesting visual layout. My goal is to place an SVG image in the background, with an anchor element and other elements laid out above it. The challenge I am facing is aligning the bottom of th ...

How can I add text to a bar or table using CSS/HTML?

I am trying to create a design similar to this: http://img291.imageshack.us/img291/5571/bartablestyling.png Currently, I only have the top bar in place. When I attempt to add text, it ends up below the profile picture. I want to avoid using float:left ...

Is it possible to use PHP to retrieve and display an entire webpage from a separate domain?

Currently, I am working on a PHP program that allows me to load a complete webpage and navigate the site while remaining in a different domain. However, I have encountered an issue with loading stylesheets and images due to them being relative links. I am ...

The functionality of WrapAll is not functioning properly in React JS

$('p').wrapAll($('<div class="wrapper"></div>')); .wrapper { background: #EEE; margin: 10px; padding: 5px; border: 1px solid black; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery. ...

Creating a chat interface with chat bubbles in React JS can be done by implementing components such as Message

Having some JSON data stored in dummyData, I am seeking guidance on how to position chat bubbles on the left and right based on the direction. My framework of choice is Material UI along with the context API. The attached image serves as a visual reference ...

Removing the dollar sign and retaining only the numerical values in an array using JavaScript

Using the code snippet below, I am attempting to retrieve elements by their class name in JavaScript and save them in an array. This is the current output I receive: "I received this output from the initial prices array $30.00, $20.00, $40.00" My inquiry ...

Ensure that all links are opened in a new tab

When including _blank in the a href URL, my website contains various elements like iframes and ads from Adsense, Taboola,, etc. Currently, when a user clicks on an iframe or ad, it opens in the same window. Is there a way to ensure that all URLs (includin ...

Can a hashmap variable be declared in HTML code?

Can a hashmap variable be set in HTML code? Here's an example: <form name="f1234"> <input type="text" name="map['foo1']" value="dog" /> <input type="text" name="map['foo2']" value="cat" /> </form> < ...

Spin an object on a stationary axis

Is there a method to create a similar effect using CSS, JS, or GSAP? ...

What is the reason that preventDefault fails but return false succeeds in stopping the default behavior

I'm having trouble with my preventDefault code not working as expected. While using return false seems to work fine, I've heard that it's not the best practice. Any ideas why this might be happening? if ($('.signup').length == 0) ...

Incorporate a background only if the specified condition in AngularJS is met, utilizing ng-style

I'm struggling to incorporate a background url style based on a given condition. I tried using data-ng-style, but for some unknown reason, it's not working as expected. I'm not sure where I'm going wrong. data-ng-style="true : {'b ...

Are there any alternatives to Google Charts for creating charts?

There is a restriction of only 2k queries per month, which I find insufficient. Are there any alternative classes, plugins, or tools that can be used to generate charts similar to those created by Google Charts? Thank you. ...

Enhance your photos with dynamic resizing within the original boundaries

Is there a jQuery plugin or function that allows for photo enlargement and movement within its original limits while hovering over the main product image like it is done here? ...