Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:17:15+00:00 2026-06-02T22:17:15+00:00

this is an odd one! Overview: I’m creating a web app and I’ve created

  • 0

this is an odd one!

Overview:
I’m creating a web app and I’ve created a menu similar to the one you’d find in the Facebook app. Swipe right and it reveals, left and it hides.

I’m doing this by binding a touchstart event to the body of the page, at this point I record the start point of the finger press and also bind a touchmove and touchend event. The touch move event finds the current finger position and moves a div containing the page content by setting translate3d(x,y,z) to match the finger position.

It actually works really great.

On touchend I then work out whether the finger has moved far enough to trigger the menu to be shown or for the content to return to its original position. Regardless of the choice I apply a class which in turn applies -webkit-transition: -webkit-transform etc to the content div. I then set the decided end position, once again using translate3d(x,y,z) and also set a variable that stops any further taps from working temporally.

And this is where there is a problem!

The problem:

At this point if the content is simple with basic structure i.e. an article layout page then the transition is fast and instant. However! If the content is complex, i.e. a large table of data then there is a pause, anywhere from 1 to 30 seconds… Very frustrating.

When it does eventually work a callback unbinds the touchmove and touchend events from the body and the variable that stops taps is unset, and we’re ready to start again.

I am testing on an iPad 1. There doesn’t seem to be any correlation between the speed of the swipe and how long the pause is. Neither is there any between the distance left for the content to move.

Finally, and I think this is key!
There is a button that performs the same open close action automatically (again, like facebook) which works fine, and if you do swipe, it pauses and then you tap that button it instantly starts working, albeit in the wrong direction as it toggles based on a variable that has already been set to open. It is almost like it clears some kind of animation queue and sorts itself out…

Some code:
The javascript

$body.bind({
    'touchstart': function(e){

        if( !swipeBan ){

            // Reset
            var used = false,
                triggered = false,
                dir = false;

            // Get start point
            start.x = e.originalEvent.touches[0].pageX;
            start.y = e.originalEvent.touches[0].pageY;

            $body.bind({
                'touchmove':    function(e){

                    // Get current value (will be the end value too)
                    end.x = e.originalEvent.touches[0].pageX;
                    end.y = e.originalEvent.touches[0].pageY;

                    // If we have not chosen a direction, choose one
                    if( !dir ){

                        dir = getDir();

                    }else{

                        var left = open && dir == 'left',
                            right = !open && dir == 'right';

                        if( left || right ){

                            var x = left ? maxSwipe - getDist('left') : getDist('right');

                            $content.setTransform(x);

                            used = true;
                            triggered = left ? maxSwipe - x > swipeTrigger : x > swipeTrigger;

                            e.preventDefault();

                        }

                    }

                },
                'touchend': function(e){

                    // Only go further if we are going the correct direction
                    if( used ){

                        swipeBan = true;

                        // Get ready for animation
                        function done(){

                            // Get touching!
                            swipeBan = false;

                            // Stop animating
                            $content.removeClass('animate');

                        }

                        // Add animate class
                        $content.addClass('animate');

                        // Set the value
                        if( ( !open && triggered ) || ( open && !triggered ) ){

                            $content.setTransform(maxSwipe,0,function(){
                                done();
                            });

                            $body.removeClass('closed');

                            open = true;

                        }else if( ( !open && !triggered ) || ( open && triggered ) ){

                            $content.setTransform(0,0,function(){
                                done();
                            });

                            $body.addClass('closed');

                            open = false;

                        }

                    }

                    // Unbind everything
                    $body.unbind('touchmove touchend');

                }
            });

        }else{

            e.preventDefault();

        }

    }
});

The set transform plugin you’ll see used above.

$.fn.setTransform = function(x,y,callback){

    y = y ? y : '0';

    var $this = $(this);

    if( callback ){

        $this.one('webkitTransitionEnd',function(){

             callback.apply(this);

        });

    }

    $this.css({
        '-webkit-transform':    'translate3d(' + x + 'px,' + y + '%,0)'
    });

    return this;

}

The CSS, very simple. There are other styles applied, but they are purely visual stuff:

#content.animate {
    -webkit-transition: -webkit-transform .3s cubic-bezier(.16,0,0,1);
}

Sorry for the long post, this has been bugging me a lot! It’s at the point where I’ll have to rip it out if I can’t sort the issue.

I hope someone has seen this before, and can help. (Or can see a glaringly obvious error in the code above!)

Thanks,

Will 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:17:18+00:00Added an answer on June 2, 2026 at 10:17 pm

    I solved this eventually, thought it may be useful to others!

    Don’t add any classes to the page, at all, between the end of the touchmove transition and the beginning of the transition that completes the movement.

    My process used to be:

    1. On touchstart get finger x
    2. On touchmove position element based on current position and start
      position
    3. On touch end, decide whether to continue or reverse the animation
      based on distance moved.
    4. Add a class of close or open to the parent element that determines
      the final position.

    However, adding this class forces safari to apply any style changes which is apparently quite intensive even if there are very few or even no changes. This is the reason for the pause.

    I changed my process to apply the transition using javascript instead of adding classes and it is now silky smooth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right, this is an odd one. We have a web service that returns data
This is an odd one. I added a file to a project, thought I
I guess this is an odd one, and the answer is most likely it
This is a very odd one and I'm not sure how to proceed. Basically,
This is an odd one, not one I've come across before. My project complies
This is an odd one, for whatever reason, getting the children of an element
Odd one this... The following command returns what I would expect when I run
Odd one this. I am using NHibernate with one website. I have configured log4net
Alright so this is an odd one... I have an application built in ColdFusion
Ok, this is an odd one for some reason. UPDATE is updating fields, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.