Is the transition not smooth when sliding the element up and down on mobile devices?

I have successfully implemented a modal that slides up and down when clicked using CSS and jQuery.

While it looks decent on desktop, the animation is choppy on mobile devices, especially when the modal slides down.

I have searched for solutions to achieve a smooth slide up and down effect, but I haven't found any suggestions that make a difference in my case.

The ultimate goal is to use this modal in a hybrid mobile app built with PhoneGap. The desired animation should resemble the YouTube player on iPhones. For example, when you play a video on YouTube on your mobile device, there is an arrow at the top left corner that allows you to minimize the player with a smooth animation. That's the type of effect I aim to achieve.

This is my current code:

https://jsfiddle.net/zshk3nex/1/

$(document).on('click', '.tol', function() {

  if ($('.hid-box').hasClass("easout")) {
    $('.hid-box').removeClass("easout");
    $('.hid-box').addClass("easin");
    $('.hid-box').css('top', 0);

  } else {
    $('.hid-box').addClass("easin");
    $('.hid-box').css('top', 0);
  }
});


$(document).on('click', '.minifyBtn', function() {

  if ($('.hid-box').hasClass("easin")) {
    $('.hid-box').removeClass("easin");
    $('.hid-box').addClass("easout");
    $('.hid-box').css('top', '90%');

  } else {
    $('.hid-box').addClass("easout");
    $('.hid-box').css('top', '90%');
  }

});
.holder {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: red;
  position: absolute;
  z-index: 9999;
  top: 0;
  height: 100%;
  left: 0;
}

.hid-box {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: #ff0;
  position: absolute;
  z-index: 9999;
  top: 100%;
  height: 100%;
}

.easin {
  transition: all 0.2s ease-in;
}

.easout {
  transition: all 0.6s ease-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="holder">
  <button class="tol">
  click here to show modal
  </button>

  <div class="hid-box">
    <div style="position:absolute;width:100%;height:100%;top:0;left:0;background:none;z-index:999;">
      <h1 class="minifyBtn">CSS3 slide up</h1>
      <p style="text-align:center;">
        <div style="text-align:center;" class="dsp player4" id="player4"></div>
      </p>
    </div>
  </div>
</div>

I would greatly appreciate any advice on resolving this issue.

Answer №1

Utilizing absolute properties like top and bottom for animations may not be optimal. Instead, consider using the transform property, which tends to perform better in animations and transitions.

When utilizing percentages in the transform property, the percentage is based on the element's box rather than its parent, unlike many other CSS values.

To enhance performance, it may be beneficial to refine your use of the transition property. Rather than transitioning all properties, specify only the necessary properties. For example, set it to:

transition: transform 0.2s ease-in
. This optimization can have a positive impact on performance.

Let's streamline your code a bit:

...

I've streamlined the jQuery by toggling just one class. The transition has been moved to the main element, and an active class has been added, adjusting the transform property to translateY(-100%). This will shift the element by -100% of its height.

These adjustments should improve performance, especially on mobile devices. However, the overall performance may also depend on the device's capabilities. Older devices might experience lower performance levels.

I hope this information proves helpful!

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

Tips for incorporating PHP $_SESSION data into a JavaScript file

What I've been doing is using $_SESSION['siteRoot'] to store the root address of my website (since it's part of a framework and can vary depending on how the site is accessed). The challenge now is incorporating this value into some of ...

Trigger the running of a python script by clicking a button

On my HTML page, there is a single button that is supposed to trigger the execution of a python script upon being clicked. The goal is to receive the result of the script and display it on the same HTML page. The process involves validating the return val ...

Applying jQuery .animate() to elements without specifying position: absolute

My goal is to create a website where clicking on an image triggers a dropdown menu. The jQuery method I'm using is as follows: function main() { $('#arrow').click(function() { $('.hidden').animate({ top: &a ...

In Express JS, the REST API encounters an issue where req.body is not defined

I am currently working on building a REST API with Express JS. When I use console.log(req.body), it is returning undefined as the output. Below is the code snippet from my routes.js file: const express = require('express'); const router = expres ...

Manage the angularJS user interface switch through an external event

I have implemented an AngularJS Material UI switch and I am looking to update its status based on an external event. This event occurs when a MQTT message is received on a specific topic that is published. To achieve this, I am utilizing a Node.js MQTT cli ...

City-based Address Suggestions with Google API Places

I have been struggling to find a solution to this specific issue without any luck. Your assistance would be greatly appreciated. Currently, I am attempting to implement autocomplete address functionality using Google API with the following code: var inpu ...

Guide on intercepting errors and sending the corresponding error message back to the client side using Node.js

Attempting to capture errors after utilizing Node.js to search for data in the database. However, whenever there is an error, the server consistently sends {errormsg: null} to the client side. I anticipate a more detailed explanation within the errormsg ...

Can AngularJS be integrated with prototype methods and variables?

When working with AngularJS, the majority of logic is typically based on the $scope: function Ctrl($scope) { $scope.name = "Freewind"; $scope.hello = function() { alert($scope.name); } $scope.method1 = function() {} $scope.metho ...

Converting HTML to a Text String (not for display) using Angular

When it comes to displaying HTML in Angular, there are numerous approaches available. For example, using $sce.trustAsHtml(myHtmlVariable) is one way to achieve this. However, I am interested in creating something like the following: myStringVariable = s ...

The states of both components are only being updated once the second event call is triggered within React

I am currently working with 2 functions in my project. One function is triggered when I type something into the search input, while the other one is called upon selecting a category. The initial values for the search and selectedCategories variables are an ...

Steps for accessing a particular tab on a separate webpage

I am working on a home page that includes an IFrame displaying a separate HTML page. Within the embedded page, there is a link that, when clicked, should open another page in the same IFrame with a specified tab displayed. This new page contains 3 tabs, ...

Guide on loading iframe content in a popup box

Wondering how to display iframe content within a popup div? Simply click on any link and watch the popup div open with the page URL loaded into the iframe. $(document).ready(function(){ $(".openpop").click(function(){ var x = $(this).attr('href ...

Save data in a function

I have a functionality in place that processes data received from a server through websocket. Depending on the specific page being accessed, the data is handled differently. sock.onmessage = function (e) { log(e.data); } function returnCurrentPage(m) ...

Is there a way to directly load an SVG for a leaflet divIcon without having to import it through a js file?

There is a sample Vue 2 project available at this GitHub repository I am looking to integrate an SVG into a leaflet divIcon. const cloudIcon = L.divIcon({ html: thecloud, // this.cloudSvg, // thecloud, className: 'my-custom-icon ...

JWT - Effective strategies for enhancing the user experience for a returning logged-in user

My client authentication system involves storing a JWT in `localStorage` once the user is verified. However, I'm not satisfied with the current user experience when a returning user is redirected straight to a new page without warning. window.locatio ...

Reordering divs in one column with CSS Flexbox to transition to a two-column layout upon resizing the screen

Exploring the world of Flexbox, I'm not entirely convinced it's the right solution for my layout challenges. Here's what I have in mind: In a 940px wide space, I need to create three columns with fixed widths of 300px each. However, on medi ...

Error: Uncaught [🍍]: The function "getActivePinia()" was invoked without an active Pinia instance present. Ensure that you have called "app.use(pinia)" before attempting to utilize a store

I encountered an issue while trying to access a store in Pinia for my Vue web application. Despite installing Pinia and setting app.use(createPinia()), I keep receiving the following error message: Uncaught Error: [ ...

Using PHP to query the database and render text and links in the menu

On my website, users currently choose an "event" from a dropdown menu that is populated from a database (Check out the code below). Once a user selects an event from the menu, I want to display text links or a second dropdown menu with the "locations" ass ...

Creating a C# view model with jQuery integration

I am facing an issue with binding a list property of a view model using jQuery. The view model in question is as follows: public class ToolsAddViewModel { public string Tools_Name { get; set; } public string Tools_Desc { get; set; } ...

Unable to position the button next to the search bar

I'm struggling to get my search bar aligned next to my dropdown button. I've tried various alignment methods without success. Both buttons are within a container, causing the search bar to span 100% of the container's width. I also attempted ...