Using jQuery to add animated transitions with translate3d

I've been attempting to use Jquery 2.1.1 to animate translate3d over a period of 10 seconds. However, once the animation is finished, instead of smoothly transitioning, it instantly changes the CSS.

Is there anyone out there who can assist me with this issue?

This is the current code I am using:

$( ".circle" ).animate({ textIndent: 100 }, {
    duration : 10000,
    step : function() {
      $(this).css("transform","translate3d(0px, 320px, 0px)"); 
    }, 
    complete : function() {
        alert("completed the animation");
    }
},'linear');

Answer №1

To achieve smooth animation using `animate` and `transform`, you need to utilize the `step` function in jQuery's animate method. Here is a sample code demonstrating this:

$('.animate').animate({
    'opacity': '320'
}, {
    step: function (now, fx) {
        $(this).css({"transform": "translate3d(0px, " + now + "px, 0px)"});
    },
    duration: 10000,
    easing: 'linear',
    queue: false,
    complete: function () {
        alert('Animation is done');
    }
}, 'linear');

One common mistake is setting the value directly in the `step` function instead of updating it incrementally. This can be resolved by splitting the functionality into two separate functions and utilizing CSS rules creatively to control values throughout the animation. Also, ensure that the queue is set to false for simultaneous execution of animations.

You can enhance the code further like this:

$('.animate').animate({
    'opacity': '320'
}, {
    step: function (now, fx) {
        $(this).css({"transform": "translate3d(0px, " + now + "px, 0px)"});
    },
    duration: 10000,
    easing: 'linear',
    queue: false,
    complete: function () {
        alert('Animation is done');
    }
}, 'linear');

$(".animate").animate({ textIndent: 100 }, {
    duration : 10000,
    easing: 'linear',
    queue: false
});

For a working example, refer to this fiddle:

http://jsfiddle.net/Hive7/1qu2qxqh/

Answer №2

If you're looking to add some flair to your website's transitions, try incorporating the jquery.transit jQuery plugin for CSS3 animations:

$('.box').transition({ rotate: '45deg' });
$('.box').transition({ scale: 2.2 });
$('.box').transition({ skewY: '30deg' });
$('.box').transition({
  perspective: '100px',
  rotate3d: '1,1,0,180deg'
});

This plugin offers a wide range of features and is highly recommended for enhancing your web design.

Among its capabilities are delay options, vendor prefixes support, chaining & queuing functions, alternate syntax for easing/duration, usage of relative values, customization of transformation origins, and various easing effects.

Check out the demo here to see it in action!

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

Strange behavior of dropdown submenu

I've encountered an issue where my child's ul li elements are not behaving as expected, despite following advice from other sources. After days of debugging with no success, I am unable to pinpoint the problem. The image showcases the issue perfe ...

Adjust the position of a div when the div above it expands

Text is displayed with a toggle button for icons. Beneath the text, there's a pagination div with a top margin set to position it correctly below the text. However, even though it follows the text in the HTML, it appears at the left corner of the main ...

"Enhancing the appearance of sorted divs using CSS3 animations in jQuery

Looking to enhance the sorting functionality of divs using jQuery by incorporating CSS3 transition animations for smoother transitions. Encountering an issue where the CSS3 transition animation is not functioning as expected, currently investigating the r ...

Trouble with displaying days on the Datepicker

I'm currently facing an issue with my datepicker. I have a specific set of days that should be highlighted on the calendar, and it needs to be constantly updated. For example, past days are removed from the calendar automatically to keep it current. H ...

What is the best way to differentiate between words enclosed in quotation marks using colors?

Working on my shop, I've added a section for "Colors available", but now I want to color different words with different colors using Javascript, CSS, or HTML. <button onclick="getColors()">Colors Available</button> <script> ...

Troubleshooting Problems with Adjusting Left Margin Using JQuery

function adjust_width() { $('#cont').toggle(function(){ $('#cont').animate({marginLeft:'0%'}); },function(){ $('#cont').animate({marginLeft:'18.4%'}); }); } The code above is in ...

Tips for placing the footer at the very bottom of your webpage

After attempting to place the footer at the bottom, I encountered some strange behavior. I am using mui framework. I decided to create a simple example page to illustrate how the footer should be positioned. The code in app.js is as follows: <> < ...

Is it possible to conceal divs that match the selected text?

The ultimate objective is to display only the divs that contain text matching the selection from the dropdown menu. However, I believe I can achieve this goal if I can determine how to hide them first. Here's a snippet of HTML code: <select id="se ...

Submitting a multipart form via AJAX from a textarea and input fields

After attempting numerous JS codes to submit a form with multiple pieces of data (2 files and 1 textarea), I have not found a solution that works effectively. So, how can we use AJAX to send form data that is not empty to PHP? <form method="post" enct ...

The alignment of the Bootstrap 4 row is off-center

My bootstrap structure includes a row with 4 columns, initially set up with 3 columns containing icons that aligned perfectly. Upon adding a fourth column, the new addition appears slightly lower on the page compared to the rest, resulting in misalignment. ...

The jQuery function fails to refresh data after getting updated in the database

I need assistance with updating frontend data automatically when changes occur in the database. Below is the code I am currently using: <script src="https://code.jquery.com/jquery-3.5.0.js"></script> <div id="test"> <?php ...

There are two notable problems with Bootstrap 4 Tooltip. The first is that it appears when a button is clicked, and the second is that it shows up for disabled elements

I am currently experiencing an issue with my tooltip while using Bootstrap 4. In my index.html, I have the following script loaded: $('body').tooltip({ selector: '[data-toggle="tooltip"]', delay: { show: 550, hide: 0 } }); The proble ...

One more time: Utilizing AJAX to save the outcome in a variable with the help of callback (undefined)

I am facing a common problem and despite my efforts, I cannot seem to resolve it. The code snippet I have provided below is causing me trouble: function get_network_from_database(callback) { $.ajax({ type: "POST", url: "load_network.ph ...

The height of EasyAutoComplete is restricted by the designated div height

I am experiencing an issue with my EasyAutoComplete feature that displays City & PostalCode information. The problem lies in the height of the div containing the input field, which limits the visibility of the EasyAutocomplete window. Only the first elemen ...

Guide to populating a full calendar using JSON information

Implementing the FUllCALENDAR CSS template for creating a meeting calendar has been my current project. The servlet class I am using is CalendarController. However, when running it, the output appears as follows: {"events":[{"id":1,"title":"1","s ...

Creating an animation of an object using a sine wave to move it from the center in three.js

I am attempting to recreate a fascinating effect that I found on this Dribbble link: My goal is to animate the vertices of a plane in a similar fashion to what is showcased in the provided link. I understand that this effect is achieved through sine wave ...

Is there a way to decipher the time using a minimal amount of code?

Transferred to stackexchange: I have a dislike for using numerous if statements in succession, as it brings about the image of a child stacking blocks. If anyone can achieve the same functionality with fewer lines of code, that would be greatly appreciate ...

How can we stop KeyboardAvoidingView in React Native from overlapping content?

I'm working on implementing a KeyboardAvoidingView section for a signup form. I've managed to adjust the keyboard properly on both iOS and Android, but instead of increasing the view's height and scrolling up, the KeyboardAvoidingView is red ...

Updating the Animation for Datepicker Closure

While using the date picker, I want it to match the width of the input text box. When closing the date picker, I prefer a smooth and single motion. However, after selecting a from and to date, the datepicker no longer closes smoothly. I have attempted sol ...

clickable jquery elements that can be selected and enabled for right

Currently, I have implemented a jQuery selectable feature in my project. Here is the code snippet: //Selectable Functionality $(document).ready(function () { $("#Selectable_Positions").selectable({ selected: function (event, ui) { ...