creating dynamic animations using jQuery UI's position() method

Is it possible to animate from the current position to the center using the position({of:,my:,at:}) function? I'm seeking a way to automate this process rather than manually animating the CSS properties.

Answer №1

While this answer may have been valid in the past, there is now a simpler solution available.

The position method now accepts a using argument specifically designed for this purpose. Here's an example:

$(div).position({
    at: "left+50% top+50%",
    of: $(div).parent(),
    using: function(css, calc) {
        $(this).animate(css, 200, "linear");
    }
});

Answer №2

If you haven't already, take a look at the .animate() function.

Update: After gaining a better understanding of what you need, I created a jQuery plugin for this specific task. You can find it here.

Check out this jsFiddle example to see how it works.

I have now made the options customizable through an object. See the example below:

$('#clickme').click(function() {
    $('#blah').align({speed:1000,y:false});
});​

UPDATE: Removed unnecessary code to simplify things. Improved the new code by fixing offset parent positioning issues. Also included links to the git repository and updated jsFiddle with the latest version of the code.

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

Looking for recommendations on effective jQuery plugins for drag and drop file uploading?

Can anyone recommend any drag-and-drop jQuery plugins that offer similar functionality to Gmail's attachment dragging and dropping feature? I would like the ability to track the upload progress. However, I am specifically looking for options without ...

Smoothly animate the height change of dynamically inserted content within a DIV using CSS transitions

Here is the template I am currently working with: <div class='content'> {{content}} </div> Along with the following style: .content { margin-top: 30px; background-color: skyblue; width: 300px; transition: all linear 0.5 ...

Trouble getting vertical alignment to work using display:table-cell within display:table

This is my initial inquiry, so I apologize if the formatting is incorrect. Despite attempting various methods from Stack Overflow, I am still unable to properly display this content vertically centered. CSS: div.img-wrapper { display: table; height: ...

Is there a way to modify the background color of ::before when hovering over it?

I have a ul-li list and when i hover last li ::before element looks white and not so good. I want to change it when i hover the last li element. How can I achieve this? Here are my codes: <div className="dropup-content"> <ul> & ...

CSS: the enigmatic padding of absolute positioning within a table cell

I am encountering an unusual issue while attempting to position a div element absolutely inside a table-cell. In order to achieve absolute positioning, I utilize a wrapper div element with position:relative: HTML <table> <colgroup> ...

Retrieve the foreign key value linked to a primary key using JSTL

I am encountering an issue while attempting to show a sub category menu using JSTL. For a website I am developing, I have a CSS list menu type. The main menu category name is stored in a database with a primary key, and the submenu is also stored in a dat ...

ajax.php form connected to a database using php

Introduction: I am currently working on a server-side datatables library. The code snippet below is not displaying either $stmt or $row, making it difficult to identify the issue. It's frustrating because I was hoping to troubleshoot this without see ...

problem with placing text into input field

When using my search program, I am encountering an issue where there is some added space before the text once it is set into the input box after clicking on a search result. To see the problem in action, you can visit the following link: http://jsfiddle. ...

the div's width isn't getting larger

Check out my code snippet: <script> var change = function(){ alert("sam"); for(var i; i >=200; i++){ var z = String(i); var x= document.getElementById("div1"); x.style.width = z; } }; </script> < ...

View the image without needing to upload it

Can you display an image from an input type="file" on a page without actually uploading it to the server? Is there a way to copy the image into a location that the script can access in order to achieve this? It doesn't matter if it loads after a refr ...

Focusing on the final (but not ultimate) elements within a specified tag

I am facing a challenge with an HTML structure containing multiple instances of a certain element along with two p elements beneath each: <some_tag></some_tag> <p></p> <p></p> <some_tag></some_tag> <p> ...

Tips for utilizing an array within React and transforming it into a component

I've developed a website that pulls data from a SQL database I created, containing details such as name, address, and occupation of individuals. I successfully managed to showcase this information on the webpage by structuring an array and inserting t ...

Creating a unique, random output while maintaining a log of previous results

While working on a recent project, I found myself in need of a custom Javascript function that could generate random numbers within a specified range without any repetitions until all possibilities were exhausted. Since such a function didn't already ...

Requesting footer details to be displayed within the header section using jQuery dataTables

I'm currently working with jQuery dataTables and facing an issue. Due to a large number of records, I need to display footer information "Showing 1 to 2 of 2 entries (filtered from 3352 total entries)" in the header section right after the "Show Entri ...

Listening to changes in a URL using JQuery

Is there a way to detect when the browser URL has been modified? I am facing the following situation: On my webpage, I have an iframe that changes its content and updates the browser's URL through JavaScript when a user interacts with it. However, no ...

What steps can I take to create a responsive jQuery UI buttonset?

I am currently facing a challenge with my web app (http://www.tntech.edu/cafe-menu.php) which is being iframed into a mobile application developed by ATT. The button sizes vary on different phone models, and I am seeking a solution to make them responsiv ...

Enclosing Functions Within Anonymous Functions - JavaScript

Recently, I've delved into the world of using anonymous JavaScript functions and have a query regarding their usage with event listeners through jQuery. For instance, I have the following event listener that triggers actions upon the submission of a ...

Using Jquery and AJAX to display results during the execution of a time-consuming operation in PHP

Good day. I am experiencing an issue with my code where, upon submission, data is sent to a PHP file that checks the health status of multiple network nodes. The problem I am facing is that it takes around 40 seconds for the tasks to complete and during t ...

Utilizing the MVC ASP.NET framework, execute an Ajax form submission to obtain a JSON response

I am experiencing an issue with an Ajax form in MVC asp.net. After submitting the form and attempting to return a json result from the action, my Onsuccess function is not triggering and the view is not being displayed. Instead, only json objects are being ...

What is the best approach to manage various json data specific to each jquery tab?

Within my webpage, I am utilizing three different (jQuery) tabs: Overview Pricing Destination info Each of these tabs houses completely unique sets of data. By specifying a URL in the href attribute, I can trigger an AJAX call to retrieve this data. How ...