Animating Swipes with CSS3

Currently, I am in the process of developing a mobile application framework using HTML 5, CSS3, and jQuery. The layout for the 'screens' markup is structured as follows:

<div class="page" id="home">
    <!-- content goes here... -->
</div>
<div class="page" id="lists">
    <!-- more content goes here... -->
</div>

My approach involves using jQuery to identify the first div element on the page and assign its class attribute as current. Subsequently, I have implemented CSS rules to hide all page elements except for those with the class current:

div.page {
    display: none;
}
    div.page.current {
        display: block;
    }

Upon detection of a hash change event in the browser (window.onhashchange), the following jQuery code is executed:

if(window.location.hash)
{
    var the_hash = window.location.hash.substring(1);
    if($('#' + the_hash).length > 0)
    {
        $('.current').removeClass('current');
        $('#' + the_hash).addClass('current');
    }
}
else
{
    $('div').eq(0).addClass('current');
}

While this functionality effectively displays the clicked anchor element, I am now interested in adding a CSS transition (such as a slide transition) to enhance the user experience. Rather than utilizing jQuery and animate(), I would prefer to leverage CSS3 animations (specifically transitioning transforms) due to the hardware acceleration they offer on iOS devices.

I am seeking guidance on how to implement an animation that slides the current div from right to left while simultaneously revealing the new one, within the existing markup structure.

Answer №1

One easy method involves assigning an additional class to hidden pages, for instance .offscreen-left and .offscreen-right, positioning the page just off the screen. This can be done utilizing the left: CSS property.

When bringing the page onto the screen, simply swap out the .offscreen-left class for .current.

If you wish to include an animated transition, you'll need to have a CSS rule for the .page class like:

-webkit-transition: left 1s linear;

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

Instructions on creating a transparent navigation bar with a back button and ensuring that the webView extends to the edge of the status bar

Can anyone provide a solution for making the navigation bar transparent with a back button and ensuring that the webView goes all the way to the edge of the status bar? All my webview constraints are currently set to the edge of the Superview. I attempte ...

Introducing an alternative solution for handling tasks linked to the completion of CSS3 animations

In order to incorporate smooth CSS3 animations into my website, I have implemented the animate.css library created by Dan Eden. One particular scenario involves a loading screen that features a fade-out animation. It is crucial for this animation to comple ...

Showing a div with a smooth fade-in effect while switching its display property to inline using jQuery

Currently, I am working on a project that involves implementing a "side pop up". To ensure it doesn't flicker like it does with jQuery's "hide()" method, I want to start by setting the display property to none using CSS. My main question is: - Ho ...

Why doesn't the WordPress Genesis child-theme inherit the parent CSS styles?

I am new to using the Genesis framework and I find myself confused about its child themes. The Genesis theme comes with its own stylesheet, but in order to use Genesis, you need to install a child theme. However, the child themes I have come across (such ...

Stopping CSS animations at a specific point along the path without using timing functions can be achieved by implementing a targeted

Is there a way to pause an animation at the 50% mark for 2 seconds and then resume? P.S. The setInterval method is not recommended! function pauseAnimation() { document.getElementById("0").style.animationPlayState = "paused"; }; var pauseInterval = set ...

My search field in Safari (desktop) doesn't respond to jQuery's .focus() function

My website has a hidden search field that appears when the user clicks on the search icon. I want to automatically bring focus to the search input so users do not have to click twice. This feature works perfectly in Chrome, but not in Safari (desktop). I t ...

Issue with Bootstrap 5 spinner's lack of motion in Firefox browser

Essentially, the issue is that a very simple Bootstrap 5 spinner does not spin in Firefox. It works fine in Chromium and all other Bootstrap components work well in Firefox as well. Here is the html code (identical to Bootstrap docs): <div class=&q ...

jQuery Fullcalendar displays the date December 25, 2011 incorrectly as January 25, 2012

I've noticed that all the dates I input into fullcalendar seem to be displaying a month ahead. For example, 10 shows as November and 11 shows as December. Does anyone have an idea why this may be happening? If you need to see any of my code, just let ...

Creating clones of <li> elements using JQuery and appending them to the end of a <ul> list

I have a regular ul li list and I am looking to add an additional li based on the first one in the list. Here is the HTML: <div id="gallery"> <ul> <li>Point Nr 1<p>lol</p></li> <li>Point Nr 2</li> <li> ...

Trouble with retrieving data from Firebase in Swift 3

Something puzzling is happening to me. I have configured a Firebase DB with some data. Here is the struct setup: import Foundation import FirebaseDatabase struct newTracks { let name: String! let trackId: Int! let postcode: String! let trackType: Stri ...

Displaying negative values highlighted in red on Datatables platform

After successfully integrating the datatables on my VF page, I now have one final requirement: to display any negative values in red and bold within numerical columns. In my Salesforce implementation, I am using <apex:datatable> for my table. Each nu ...

Issue with Chrome related to svg getScreenCTM function

Check out the jsFiddle demo I am attempting to utilize the getScreenCTM function to retrieve the mouse position based on SVG image coordinates. It seems to work in IE and Firefox, but not in Chrome. When I define the attributes width and height in the SV ...

Place the sorting image on the left side of the DataTable header

I am currently using DataTable in my code. The sorting images in the header of the table are on the right side while the labels are on the left, as shown below: https://i.sstatic.net/Bz6EO.jpg However, I would like to switch this arrangement and have the ...

Retrieve the complete HTML content of a webpage, including the values of all input fields

I'm attempting to save the entire webpage as an HTML file, including all previously entered values in input fields. I have already tried this method: $("#content").html(); However, it does not retain the values entered into input fields. $("#conten ...

Tips for creating animations with multiple elements that share the same classes

I am trying to create expandable boxes that can open onclick and close again by clicking on the X. The issue I'm facing is that the close jQuery function isn't working. However, my main concern is how to optimize the code so it doesn't becom ...

The process of retrieving CSS attributes from a control found by XPath using Selenium IDE

During my Selenium IDE script execution, I am looking to identify and handle an error state. This specific error state is visually highlighted on the page with a select control changing its background color to a light shade of red. The xpath for the selec ...

Retrieve the $http data from a function that is external to it

Apologies if the title is confusing, it's hard to explain in a different way. The situation I have is... app.controller('viewProductController', ['$scope', 'dataFactory', '$routeParams', function($scope, dat ...

Next.js - Anticipated that the server HTML would include a corresponding <div> within <div> tag

For a live demonstration, please click here In my current project, I am experimenting with creating a simple layout that adjusts based on the user's screen size. Specifically, on mobile devices, only the latest posts should be displayed. On desktops, ...

What is the best method for retrieving values from selected radio buttons?

I am trying to retrieve the values of the selected radio buttons with the name is_external example.html <div class="exter_inter"> External <input type="radio" name="is_external" value="1" <?php if(isset($_GET['status']) &&am ...

Steps to display JSONP response delivered by PHP on a web page

I've written a JSONP script as shown below: <script> $(document).ready(function(){ $("#LoginForm").submit(function(){ var data = $(this).serialize(); //alert(data); $.ajax({ type:"POST", dataType:"jsonp ...