iOS experiences sluggishness with translate3d

I have a current project focused on iOS devices, where I am utilizing translate3d to enable object movement on the page through user drag interactions.

Interestingly, I noticed that when viewed in Chrome or Safari, the box moves smoothly around the screen. However, this smoothness is not replicated when viewing it on an iPhone or iPad. While CSS transitions with translate3d generally provide smooth transitions on iOS devices, I'm puzzled as to why this issue persists. Is there a solution to improve the performance?

Below is the snippet of my JavaScript code: (JSFiddle link: http://jsfiddle.net/Ls4uc/10/)


var tStart, loc, rdy;
$(".box").bind("mousedown touchstart", function (e) {
    tStart = e.type == "mousedown" ? event.clientX : event.touches[0].pageX;
    tStartY = e.type == "mousedown" ? event.clientY : event.touches[0].pageY;
    tStartTranslate = getTranslateParams($(this), "x");
    tStartTranslateY = getTranslateParams($(this), "y");
    $(".log").text(tStart);
    rdy=true;
});
$(".box").bind("mousemove touchmove", function (e) {
    event.preventDefault();
    if(!rdy){return;}
    loc = tStart - parseInt(e.type == "mousemove" ? event.clientX : event.touches[0].pageX);
    locY = tStartY - parseInt(e.type == "mousemove" ? event.clientY : event.touches[0].pageY);
    $(this).css({"-webkit-transform": "translate3d(" + parseInt(Math.ceil(tStartTranslate) + (-loc), 10) + "px," + parseInt(Math.ceil(tStartTranslateY) + (-locY), 10) + "px,0)"});
});

function getTranslateParams(obj, xy) {
    var paramsArray = $(obj).css('-webkit-transform').substring(7, $(obj).css('-webkit-transform').indexOf(')')).split(',');
    if (xy !== "x" && xy !== "y") {
        return false;
    }
    return xy == "x" ? paramsArray[4] : paramsArray[5];
}

Answer №1

To achieve the desired effect, apply the following CSS properties to elements within the .container: -webkit-perspective:1000 and -webkit-backface-visibility:hidden.

For instance:

.container div{
-webkit-perspective:1000;
-webkit-backface-visibility:hidden
}

This configuration is effective in iOS 8, however in iOS 9...

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

Is there a way to circumvent the eg header along with its contents and HTML code using JavaScript?

I have a script in JavaScript that is designed to replace the content of data-src attribute within each img tag with src. However, I am facing an issue where this script interferes with the functionality of a slider located in the header section. The sli ...

Guide to adding a 3D effect or utilizing MKMapCamera features within MKMapView on iOS 6

Currently, I'm implementing MKMapCamera in my iOS 7 navigation application for a 3D effect. However, I am facing challenges when trying to implement the same effect in iOS 6 Maps. Unfortunately, I haven't been able to find a solution for achievin ...

Jest: Mastering the art of testing a MongoDB-powered JavaScript service

As a newcomer to Jest, I am navigating my way through using Dependency Injection with a UserService. public async getAll() { const userRecords = await this.userModel.find().select('name').catch((e) => { throw new HttpException(500, &apo ...

JavaScript is unable to modify the value of an input in HTML

function modifyComment(id) { var pageID = "<?= $ID ?>"; var commentID = "p" + id; console.log(id); console.log(commentID); console.log(pageID); var commentContent = document.getElementById(commentID).innerHTML; < ...

click events in backbone not triggering as expected

It's puzzling to me why this is happening. The situation seems very out of the ordinary. Typically, when I want an action to be triggered on a button click, I would use the following code snippet: events:{ 'click #button_name':'somefun ...

How to create a custom CSS style to make Bootstrap 4 modal slide in from the bottom

Back in the days of Bootstrap 3, this was the trick: .modal.fade .modal-dialog { -webkit-transform: translate3d(0, -25%, 0); transform: translate3d(0, -25%, 0); } Another approach that could have been used: .modal.fade .modal-dialog { transfor ...

The query datetime picker is unable to retrieve the date when called in a different function

Could you please clarify why I am receiving an "undefined" value in the second alert of the loadchart function call? What is causing the error here? I am encountering an issue with fetching dates from a date timepicker while using Bootstrap. Below is my ...

Issue with radio button click function not working on IE and Firefox

I am working with a form that has multiple inputs and radio buttons. Within the form, there are Yes & No radio buttons. When the "Yes" radio button is selected, additional data slides down below. HTML: <div class="item seperator first clearfi ...

Implementing jQuery to add content within Redactor

I am working with a textarea field that has an ID of "description", however, it is being rendered by a WYSIWYG editor called Redactor. I am trying to use jQuery to input something in the textarea. So far, I have attempted: $('#description') ...

Can anyone suggest a more efficient approach to handling variations using CSS?

Within the message component, there are currently only two variants available: error and success. This project is built using vue3 script setup and utilizes SCSS for styling. <script setup lang="ts"> defineOptions({ name: 'Notificat ...

Mongoose: strange outcomes observed when trying to delete the final element from an array

Update: I made a change in my approach by filtering the array directly and saving it instead of using updateOne and $pull. Surprisingly, this fixed the issue of html elements getting removed. However, the same problem persists when deleting the last item i ...

Setting up a service in angularjs that is reliant on another service

One thing I'm trying to figure out is how to utilize a service like $http outside of the $get function. Is this even possible? Currently, my code loads a json file that contains a dictionary used by my application in various ways. I want users to have ...

Create a layout where a flexbox container is nested under another div and achieve the desired positioning

<style> .container{ display: flex; gap: 5px; flex-direction: row; justify-content: space-around; flex-wrap: wrap; overflow:auto; } .container .one{ background-color: blue; ...

Transitioning to the UITableViewController will entail an exploration of the navigation bar

I am facing an issue with a segue in my iOS app where a UIViewController transitions to a UITableViewController by coming in from the bottom of the screen, but it covers the navigation bar. The hierarchy of my views is: Navigation Controller (initial view ...

Using Flexbox for Input Elements Causes Additional Margins in Webkit Browser

My form has a straightforward layout with an email field and a submit button. I am using a flexbox design for this form, which is working well overall. However, I have noticed that there seems to be some extra spacing added next to input elements in webkit ...

What is the best method for extracting a nested json value without a key?

Is there a way to retrieve a specific value from a nested JSON object that does not have a key? I'm attempting to access the "2019-03-19T22:57:47.972Z" value within this JSON structure: var json = {"metaData":[{"name":"ACTION_NAME"},{"name":"SENT_RE ...

What is the best method for invoking a JavaScript function when the view changes in AngularJS?

On the transition from one AngularJS view to another, I am looking to execute a few JavaScript functions such as a placeholder fallback. Is there a way to accomplish this on a global scale? ...

The handleChange function fails to trigger when selecting a date using Material UI components

I am currently facing an issue with the material ui datepicker. When I click on a date, the selected date is not chosen and the date window does not close. I suspect this is due to passing the date into another file and the handleChange function (from Form ...

Creating visual representations of class, organization, flow, or state diagrams using Vega or Vega-lite

I'm struggling to find an example of a state, class, flow chart, or org chart diagram created with Vega. Are there any available online? Vega seems like the perfect tool for this type of visualization, although it may be a bit complex. Without a star ...

Trying onClick and addEventListener, but nothing seems to be working

Hey there, can someone help me figure out why my deck of cards isn't displaying when the "audiobooks" link is clicked? I've tried various solutions like using onclick in the a tag to call the function and applying eventListener the other way arou ...