Sliding views in CSS using ui-router

I want to create a sliding in/out effect for my views similar to what is demonstrated here:

Here is the Plunker I have created: http://plnkr.co/edit/ST49iozWWtYRYRdcGGQL?p=preview

However, when I copy the CSS from the link above, my entire ui-view disappears and I suspect it may be related to the position: relative in my container

CSS:

*,
*:after,
*:before {
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html {
  font-size: 62.5%;
  min-height: 100%;
  position: relative;
}
html body {
  font-size: 140%;
  line-height: 1.5;
  margin: 0;
  padding: 0 0;
  margin-bottom: 60px;
}

.container {
  max-width: 430px;
  margin: 0 auto;
  position: relative;
  display: block;
  float: none;
  overflow: hidden;
}

.l-one-whole {
  width: 100%;
}

form {
  background: #f0f0f0;
  height: 350px;
  padding: 10px;
  font-size: 1.4em;
}

CSS needed to add:

.slide {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}
.slide.ng-enter,
.slide.ng-leave {
    -webkit-transition: all 1s ease;
    transition: all 1s ease;
}
.slide.ng-enter {
    left: 100%;
}
.slide.ng-enter-active {
    left: 0;
}
.slide.ng-leave {
    left: 0;
}
.slide.ng-leave-active {
    left: -100%;
}

HTML:

<body ng-controller="MainCtrl">

  <ul>
    <li><a href="#/view1">view1</a>
    </li>
    <li><a href="#/view2">view2</a>
    </li>
  </ul>    

  <main class="l-one-whole">
    <section class="container">
      <article class="l-one-whole">

        <div ui-view class="slide"></div>

      </article>
    </section>
  </main>

</body>

JS:

var app = angular.module('plunker', ['ui.router', 'ngAnimate']);

app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('view1', {
      url: '/view1',
      templateUrl: 'page1.html'
    })
    .state('view2', {
      url: '/view2',
      templateUrl: 'page2.html'
    });
  $urlRouterProvider.otherwise('/view1');
});

Any assistance would be greatly appreciated.

Answer №1

Could this be what you've been searching for? Check out the link here: Plunkr

To achieve smooth animations, I incorporated the following styles:

/* Transition effects */
.l-one-whole {
  position: relative;
  overflow: hidden;
  min-height: 400px;
}
.slide {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.slide.ng-enter,
.slide.ng-leave {
  transition: all 1s ease;
}
.slide.ng-enter {
  transform: translate(100%, 0);
}
.slide.ng-enter-active {
  transform: translate(0, 0);
}
.slide.ng-leave {
  transform: translate(0, 0);
}
.slide.ng-leave-active {
  transform: translate(-100%, 0);
}

In place of using left, I opted for utilizing transform because it allows browsers to boost animation performance by employing GPU acceleration.

I trust nothing has been overlooked in my implementation.

Answer №2

Outcome: http://plnkr.co/edit/vhGSiA?p=preview

I decided to go with Angular 1.3.15 over 1.2.9

Here's the streamlined HTML code snippet:

  <section class="container">
    <div ui-view class="slide-left"></div>
  </section>

Additionally, here are some CSS adjustments I made:

.container {
    overflow: hidden;
    position: relative;
}
.slide-left.ng-enter, .slide-left.ng-leave {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  transition: transform .7s ease-in-out;
}
.slide-left.ng-enter {
  z-index: 101;
  transform: translateX(100%);
}
.slide-left.ng-enter.ng-enter-active {
  transform: translateX(0);
}
.slide-left.ng-leave {
  z-index: 100;
  transform: translateX(0);
}
.slide-left.ng-leave.ng-leave-active {
  transform: translateX(-100%);
}
form {  /* contents within ui-view */
  position:absolute;
}

Answer №3

Modify

<script src="https://raw.github.com/dlukez/ui-router/angular-1.2/release/angular-ui-router.js"></script>

as:

<script src="https://cdn.rawgit.com/dlukez/ui-router/angular-1.2/release/angular-ui-router.js"></script>

Revised plnkr

Detailed explanation can be found here:

Guidance on linking and running external JavaScript file hosted on GitHub

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

Grid Refresh Spinner Update

Our Vaadin Grid features a settings icon that when clicked, opens a window allowing users to select/deselect columns. Upon closing this window (triggering our custom window event), the main window's columns are updated accordingly. Now, my requirement ...

Embedding complex JSON information into an HTML dropdown menu

Here is a JSON string that I am working with: { "electronics": { "cameras": [ "sony", "nikon", "canon" ], "TV": "none", "laptop": [ "hp", "apple", "sony" ] }, "home": { "furniture": [ ...

Next.js and Material UI - issues with dynamic styles not functioning

I recently started using Next JS in combination with Material UI, following the example project setup provided in the documentation on Github: https://github.com/mui-org/material-ui/tree/master/examples/nextjs My main objective is to utilize Material UI&a ...

When attempting to include fit="true" on ui-gmap-markers, a.lat does not function properly

It seems I am encountering an error that reads "TypeError: a.lat is not a function." I'm not sure why this is happening, so any assistance would be greatly appreciated! Below is the stack trace: TypeError: a.lat is not a function at oh.extend (main. ...

The Google Language Translator disregards the formatting

Currently, I am in the midst of developing a website with Wordpress and have successfully integrated Google Language Translator. Everything seems to be working well, except for one issue - when I translate the content, it alters the font size. Prior to tra ...

What is causing the :active property to fail to work properly?

I'm currently working with Bootstrap, but I'm experiencing an issue with applying the :active state as a background color. It's not showing up, although it is changing the text color. Here is the HTML code: <button class="btn btn_sty ...

The child element with the specified position within the id element

Is it possible to highlight 'The second paragraph' of p id="dd" using nth-child? I noticed that when I add "#dd" in styles, it stops working properly. <!DOCTYPE html> <html> <head> <style> #dd p:nth-child(3) { back ...

Using the `ng-if` directive in Angular to check for the

I need to output data in JSON format using items. To display a single item, I utilize ng-repeat="item in items". Additionally, I can access the user object of the currently logged-in user with user. Every item has the ability to belong to multiple wishlis ...

What could be the reason for the lack of controller updates despite changes made to the service

Could someone please help me solve the issue with my code? I expected that after clicking the button, the text would be updated. However, it seems to not be working as intended. Any assistance you can provide would be greatly appreciated. main.js x = a ...

Why do certain full screen websites not align with my screen width properly?

When I use my 1920px wide screen and inspect the HTML tag with Chrome DevTools on websites like Firebase or Facebook Messenger, I notice a difference: https://i.sstatic.net/1nknq.png Despite my screen width being 1920px, these websites appear fullscreen ...

Unable to modify variable values in AngularJS

I'm currently utilizing AngularJS along with the "Angular Material" implementation (found here: https://material.angularjs.org/latest/#/) One of the components I'm using is the SideNav component: https://material.angularjs.org/latest/#/demo/mate ...

"Enhance your design with a cutting-edge gradient button using CSS

While exploring gradient effects in CSS, I stumbled upon this unique button design. After extensive searching on the internet, I couldn't find a solution on how to recreate the same button effect using CSS. Is it possible to create it using CSS?Button ...

Is there a way to have a single background image fill the entire screen?

Can someone help me with my Offcanvas navbar created using Bootstrap? I added a background image from Google as the URL, but instead of one whole piece, it's appearing as 6 duplicate images. What could be the issue here? I tried looking for solutions ...

Successfully resolved: Inability to dynamically adjust button color according to its state

Currently I am working on a feature where a button changes color when it is disabled, but also has a custom color when enabled. Here is the code snippet I am using: Despite setting blue text for the button, it remains blue even after becoming disabled. Ho ...

Creating a dynamic element in real-time with CSS

I need help with a styling issue involving multiple spans enclosed in a center tag. I want each span to enlarge when hovered over by a user, but the problem is that when I increase the size of one span, it pushes aside all the other elements and disrupts t ...

The width of an HTML input and button elements do not match

Currently, I am facing an unusual issue where my input and button tags seem to have the same width assigned to them (width: 341.5px; calculated from $(window).width() / 4) in the code, but visually they appear to be of different widths. Here is a visual re ...

Alert: The specified task "taskname" could not be located. To proceed with running grunt, consider using the --force option

My current task involves converting .css files to .sass files using the 'grunt-sass-convert' npm module. Here is the configuration in my 'Gruntfile.js': 'use strict'; module.exports = function(grunt){ grunt.loadNpmTasks( ...

Issue with Bootstrap 3 columns not arranging correctly

Utilizing Bootstrap 3, I am attempting to stack grids on top of each other in the order of A, B, C, D, E. While the mobile grid stacking works well, the issue arises when viewing it on desktop where the grids do not align as expected, particularly the box ...

Display Listings Shortcode with Responsive CSS styling

I recently added a plug-in called Display-listings-shortcode and incorporated the columns-extension feature on my website, RitaNaomi.com. This allows for blog posts to be displayed in columns halfway down the homepage when viewed on a web browser. Initiall ...

Have you ever noticed how Angular-cron-jobs consistently produces identical cron expressions for tasks such as "Every Minute," "Every Hour at 0 past hour," "Every Day at 0:0," and so on?

If you experiment with DEMO BASIC on , you will notice that "Every Minute", "Every Hour at 0 past hour", "Every Day at 0:0", and "Every Week on at 0:0" all result in the same expression: *****. A similar issue arises when selecting Every Year, as regardle ...