Animate elements with jQuery, moving them from the bottom right corner to the

I am currently working on a project to create a responsive webpage that involves clicking on a circle in the middle of the screen and having a div enlarge from the circle to the top left corner of the webpage. To achieve this effect, it seems like I would need to use a negative height value. I have spent considerable time searching online for a solution to this challenge, but so far have not been able to find one even though it seems like a common issue...

While the following code snippet is not operational, it gives an idea of what I am trying to accomplish:

$(".corner").click(function(){
    $(this).animate({width: '-400px', height: '-400px'}, 1000);
});

Answer №1

It seems like there may be a glitch in your current approach, so I've devised an alternative solution. This method involves resizing the div to +400px by +400px and adjusting its position accordingly, as opposed to using negative values for width and height.

Below is the modified JS code based on your initial script:

$(".corner").click(function(){
    $(this).css({position: 'relative'});
    $(this).animate({right: '400px', bottom: '400px', width: '400px', height: '400px'}, 1000);
});

Additionally, here is a supplementary JSFiddle demonstrating the concept. In this example, I have used a square div instead of a circle and added margin to allow it to expand upwards and to the left. I hope this clarifies the concept for you.

I would appreciate your feedback on this approach.

Answer №2

If you want to achieve this,

$(".box").click(function(e){
    $new_width = $(e.target).width() + e.clientX;
    $new_height =  $(e.target).height() + e.clientY;
    $(e.target).animate(
        { top:0, left:0, width: $new_width, height: $new_height }, 1000
    );
});

Check out this example on jsfiddle

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

Employing Bootstraps data-spy and data-toggle features with a button

Is it possible for a button to not only toggle a hidden accordion but also scroll the page to that section? Currently, my code is working great with navigation, but I'm struggling to make the button display text and scroll to the top of the section. ...

What is the best way to connect added elements together?

I am currently utilizing Plupload to upload files. Due to specific requirements, I need to place FilesAdded "inside" init as demonstrated below. The issue I'm facing is the inability to utilize jQuery.remove() on elements that have been appended usin ...

What is the best way to utilize data attributes of select options when applying a jQuery filter?

I'm currently working on implementing a dependent dropdown feature without being able to use the value attribute. I came across a codepen that does exactly what I need, although it uses value. So I decided to fork it and modify the value attribute to ...

The alignment of the label button within the form-group is being set to the top

While using Bootstrap 4, I encountered an issue with aligning the save button in a form group because there was no label at the same level. Despite trying to follow an example from here, I still had to hard code margin-top to prevent the button from bein ...

Entire body encompassing table

I am trying to create an HTML page with a table that spans the entire body and displays scrollbars when needed for both horizontal and vertical scrolling. Here is my current styling for the table: table { box-shadow: inset 0 0 10px #000; position: ...

Vertically center the container

I am struggling to center my container div vertically, similar to how it is horizontally aligning with margin: auto;. Despite searching online for solutions, I have not been successful in finding a method that works for me. It is surprising to me that in t ...

Achieving perfect alignment both horizontally and vertically using CSS3's viewport height of 100%

I'm trying to utilize CSS3's Viewport Height to create a fullscreen section with a height of 100vh. However, I am encountering difficulties in centering elements both horizontally and vertically within the section. My goal is to have an image and ...

Guide to setting up collapsible sections within a parent collapsible

I came across this animated collapsible code that I'm using: https://www.w3schools.com/howto/howto_js_collapsible.asp Here is the HTML: <button type="button" class="collapsible">Open Collapsible</button> <div class="content"> &l ...

Repeater embedding a Div

I'm currently attempting to access a hidden div within my repeater by clicking a button that is also located within the repeater. The hidden div is set to display as none, and the button contains a jQuery script triggered on OnClientClick. Here' ...

Automatic Clicks in the Chrome Console

I've come across a website that requires me to click on multiple elements scattered throughout the page Here is the code for one of the elements: <span class="icon icon-arrow-2"></span> Is there a way to provide me with the console comm ...

Retrieving Files using Ajax Across Different File Types

I recently came across the following code snippet: DOM_imgDir = "img/UI/DOM/"; fileextension = ".jpg"; $.ajax({ url: DOM_imgDir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { filename = thi ...

Using CSS to create hover effects for specific classes of elements

Is there a way to make the button change color on hover when hovering over anywhere in the navigation bar (.topNav) instead of just when hovering over the individual button elements (.top, .middle, .bottom classes)? I tried using span to achieve this, but ...

Information flows from the Bootstrap 4 template

When viewed on a mobile device, the content extends beyond the page and a horizontal scrollbar appears. You can view my page by clicking this link. <div class="custom_content col-md-12"> <div class="container"> <div class="row"> ...

What could be causing the overlap of my input box with its parent container?

Here is the code snippet I am working with: <section className="createTodo-box"> // parent <div className="createTodo-inside"> // child <Input value={this.state.text} style={{ width: '200px' }} ...

Why are the links in the navgoco slide menu failing to function properly?

I utilized a demo from jQueryRain to create a collapsible menu using jQuery. However, after completion, I discovered that none of the links were functioning properly. Upon visiting the documentation page, I noticed that many users were encountering the sam ...

In IE9, the margin: auto property does not effectively center a div element

I'm trying to center a content div in the space leftover by a sidebar. Here's how I want it to look: After some trial and error, I was able to achieve this for most browsers by using margin: auto on the specific div, along with setting overflow: ...

jQuery: Function is not running as expected

I'm facing a challenge in executing a function twice, and I'm having trouble identifying the issue. Check out my JSFiddle at the following link: http://jsfiddle.net/g6PLu/3/ Javascript function truncate() { $(this).addClass('closed&apo ...

What is the best way to "leap" a sole transform value within an animation?

I need to create an animation that makes a transform function value "jump" in an animation. Within my @keyframes rule are three percentages with the transform property in each one. I specifically want only the scale to transition from 0.5 to 1 between the ...

Revamp website to meet modern Web 2.0 standards

I am looking to revamp my old ASP classic website to meet the modern standards of web2.0 using PHP. Currently, my main website page features sections that need to display the latest updates such as recent forum threads, news articles, and user comments. In ...

The jQuery event handler fails to activate on the initial page load, however, it functions properly after refreshing the page and inspecting the DOM

Encountering a challenge with IE9 and jQuery. Click events on anchor tags function in Chrome, Firefox, and Opera, but fail to fire or have unexpected behavior in IE9. This issue only occurs upon the initial page load when the cache is empty. When clicking ...