upon reaching the conclusion of the animation without employing the .animate() method

I'm currently working on developing an iPad web application. The .animate() method doesn't meet the necessary speed requirements, so I've opted to utilize CSS for most of my transitions. How can I go about implementing

html

<div id="myGallery" class="container"></div>

css

.container {
position: fixed;
-webkit-transition: -webkit-transform 0.25s ease-in-out;
}

.pos-1 {
-webkit-transform:translate3d(0px,0px,0px);
}

.pos-2 {
-webkit-transform:translate3d(100px,0px,0px);
}
.pos-3 {
-webkit-transform:translate3d(200px,0px,0px);
}

js

$("#myGallery").removeClass("pos-" + this.previousId).addClass("pos-" + this.currentId);

$("#myGallery").bind("webkitAnimationEnd", function() {
        // this.style.webkitAnimationName = "";
        console.log("done animating");
    });

How can "webkitAnimationEnd" be effectively used to trigger the message "done animating" without relying on the .animate() method?

Answer №1

Is it possible to simply switch the element's class from one with animation to one without?

Am I interpreting the query incorrectly?

Are you asking for something different? Do you need to track when the CSS animation completes? One way could be by setting a timer and predicting the duration of the animation beforehand.

Answer №2

  1. position:fixed does not function correctly in iOS Safari; it behaves like absolute positioning. It is recommended to avoid using this property on iOS devices going forward.

  2. You can achieve the same effect using CSS3 alone by utilizing the steps() method.

Avoid relying on JavaScript or jQuery for animations in iOS as they may not yield optimal results.

Check out my code snippet with pure CSS animation on this JSFiddle link.

CSS:

@keyframes pos1{
    from{transform:translateX(200px)}
    to{transform:translateX(0)}
}
@keyframes pos2{
    from{transform:translateX(0)}
    to{transform:translateX(100px)}
}
@keyframes pos3{
    from{transform:translateX(100px)}
    to{transform:translateX(200px)}
}

.container {
    width:100px;
    height:100px;
    border:1px solid gray;
    transform:translateX(200px)
}
.pos1{
  animation-name: pos1;
  animation-duration: 0.25s;
  animation-direction: alternate;
  animation-timing-function: ease-out;
  animation-iteration-count: 1;

  transform:translateX(0)
}

.pos2{
  animation-name: pos2;
  animation-duration: 0.25s;
  animation-direction: alternate;
  animation-timing-function: ease-out;
  animation-iteration-count: 1;

  transform:translateX(100px)
}

.pos3{
  animation-name: pos3;
  animation-duration: 0.25s;
  animation-direction: alternate;
  animation-timing-function: ease-out;
  animation-iteration-count: 1;

  transform:translateX(200px)
}

Javascript

$('#p1').click(function(){
  $('#myGallery').removeClass('pos1, pos2, pos3').addClass('pos1');
});
$('#p2').click(function(){
  $('#myGallery').removeClass('pos1, pos2, pos3').addClass('pos2');
});
$('#p3').click(function(){
  $('#myGallery').removeClass('pos1, pos2, pos3').addClass('pos3');
});

HTML

<div id="myGallery" class="container"></div>
<input type="button" value="pos1"  id="p1"/>
<input type="button" value="pos2"  id="p2"/>
<input type="button" value="pos3"  id="p3"/>

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

Troubleshooting CSS3 Media Queries in Notepad++

Below is the media query I've included directly in my webpage's style sheet: @media screen and (max-width: 480px) { background-color: red; } By setting the background color to red when the screen media type has a maximum width of 480px. Howe ...

Limit the radius to only apply on big screens using tailwind css

Is there a way to apply border radius to an image only on larger screens and maintain straight edges on smaller screens? I'm working with Nextjs and Tailwind CSS. ...

Ensure the sum is recalculated whenever the input changes by using the jQuery change event

I am creating a system that requires the total values of multiple inputs to not exceed 100. I have successfully implemented this functionality, but now I need a way to automatically adjust the total if changing one input causes it to drop below 100. Here& ...

What's the deal with this loading GIF layout problem?

Styling with CSS: .smallLoaderBackground { background-image: url('loaderBackground.gif') !important; background-position: center center; background-repeat: no-repeat; position: fixed; left: 50%; top: 50%; height: 50px ...

"Even rows are the only ones being highlighted on the table

I created a table that dynamically highlights all odd rows. To achieve this, I implemented a method to identify the row number and then apply the alt class to those specific rows. In order to highlight the rows on hover, I added a simple :hover selector ...

Encountered a snag with submitting data via AJAX: received an error message stating

I created this custom script for a contact form on my website, and it seems to be working fine. However, I'm encountering an issue where instead of storing the data in my database, all I get is [object HTMLCollection]. Can someone please explain wh ...

The daterangepicker reigns supreme above all other elements

Just a heads up, I am utilizing daterangepicker from this link: . Recently, I encountered an issue where the input field was overlapping with other elements like bootstrap Modals or menus. <div class="col-md-3 form-group"> <div class=&qu ...

Sending data from Ajax to PHP

I've gone through all the previous examples without success, and now I am facing a simple php question. You can find the example here. My goal is to click on a table and have the options displayed as follows: When I explicitly declare the table name ...

Having trouble setting the selected option in Jquery by value?

I have exhausted all options found on the internet. What could I be overlooking? The desired option is not getting selected. Here is the troublesome section of code. I have also included some other attempts that I have commented out. If it helps, this li ...

Is it advisable for postcss plugins to list postcss as a peer dependency?

I'm trying to incorporate the PostCSS Sass Color Function into my project. Unfortunately, I encountered this error: PostCSS plugin error: Your current version of PostCSS is 6.0.22, while postcss-sass-color-functions requires 5.2.18. This discrepa ...

Using jQuery to alter the background position of multiple backgrounds in CSS

I'm using jQuery to dynamically adjust the background image position of an element based on screen resolution. Here's the code: var pwwidth = $(window).width(); var pwheight = $(window).height(); var bg1posx = pwwidth - $('h1.portofolio&ap ...

Choose a textarea in a generic manner

Can anyone help me with selecting a textarea from a specific element on my webpage using jQuery? I've been trying different methods without success. Here is an example of what I have attempted: JsFiddle I wanted to use the :input[type='blah&ap ...

When a page becomes unresponsive due to an overload of DOM elements in a list, causing tabs to freeze

My webpage features a two-column layout with a header containing a navigation bar and a footer. The left column is dedicated to listing items in three different tabs, each tab representing a different item type. On the right side, one or more maps are di ...

What is the best way to extract data for the x-axis and track the frequency of occurrences for the y-axis using crossfilter in JavaScript

My current project involves using crossfilter to analyze data on the x-axis and the frequency of occurrences on the y-axis. var data = [{ Owner: "Alyssa", ID: "A" }, { Owner: "Alyssa", ID: "A" }, { Owner: "Alyss ...

Ways in which AngularJS and JQuery can be utilized

I'm a programmer experienced in JQuery and now eager to delve into the world of AngularJS for my upcoming project. I recently came across this insightful answer on how to shift from thinking in jQuery to thinking in Angular. This has prompted me to ex ...

Guide on creating a menu that remains open continuously through mouse hovering until the user chooses an option from the menu

I have a unique scenario where I am working with two images. When the mouse hovers over each image, two corresponding menu bars appear. However, the issue is that when the mouse moves away from the images, the menu disappears. Any suggestions on how to im ...

Retrieve the values of the rows that have been selected in the Kartik GridView located within a modal, and then transfer

I am attempting to extract data from a Bootstrap modal (which contains a table of Kartik GridView) and pass the selected value to the parent form (an action create form). Can anyone provide guidance on how to achieve this? The modal form includes fields su ...

What could be causing the disappearance of my <Div> when applying a Class to the contained <span>?

My goal is to showcase a variable on my HTML page using CSS for a Graphical display in OBS streaming software. Whenever I apply the class .wrappers to the span id p1Name (and p2Name), the text disappears from the HTML output in OBS. I'm puzzled as to ...

Error message: "PHP encounters an issue with jQuery due to absence of 'Access-Control-Allow-Origin' header"

I am currently attempting to make an external API call in PHP using AJAX and jQuery, but I keep encountering the error message saying "No 'Access-Control-Allow-Origin' header is present". The API does not support JSONP. Is there any workaround t ...

Learn how to smoothly scroll to the top of a div by clicking on a team name

CSS Code .hover-div { position:absolute; margin-top:-150px; visibility:hidden; transition:all 0.5s linear 0s; } .team_hover:hover + .hover-div { margin-top:0px; visibility:visible; } .hover-div:hover { margin-top:0px; visi ...