Flex sliding side bar with UI router

I'm working on implementing a sliding side-bar feature, but I've run into an issue where the main view snaps into place while the side bar slides in. To better illustrate this problem, I've set up a demonstration on Plunkr. The body doesn't move along with the side-panel as expected. How can I resolve this issue?

body:

<div class="container">
  <div class="child">
    <a href ui-sref="main.sidePanel">show side panel</a>
  </div>
  <div ui-view class="slide"></div>
</div>

side-panel:

<div class="side-panel-body">
  <a href ui-sref="main">hide side panel</a>
</div>

css:

.container {
  display: flex;
  height: 400px;
  padding: 20px 0;
}

.child {
  background: yellow;
  flex: auto;
}

.side-panel-body {
  width: 400px;
  height: 100px;
  background: lightgray;
}

.slide.ng-enter,
.slide.ng-leave {
  transition: all 2s 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);
}

Answer №1

Explaining transformations in a nutshell, translating a DOM element does not affect other DOM elements.

Imagine a flexbox with two divs - everything is working smoothly. As you resize the window, the left div expands to fill the space, thanks to its flex: auto setting, while the right div remains at a fixed width of 400px.

When you use transform: translate on the right-hand div, it only visually shifts it without impacting its actual position within the container or affecting the left-hand div. However, once you hide or remove the right-hand div, the left-hand div will then expand to fill the flexbox.

To achieve your desired effect, you would need to animate both divs - adjusting the size of the left one and translating the right one. Alternatively, you could alter the width of the right-hand div directly and let transition: all 2s ease; handle the animation for you.

Answer №2

Big shoutout to @CH Buckingham for helping me find a solution. It may not be exactly what I had in mind, but it gets the job done without being too hacky. With this setup, you can toggle the sidebar using a scope variable while still having the flexibility of content with ui-router.

<div class="container">
  <div class="child">
    <a href ui-sref="main.sidePanel">show side panel</a>
  </div>
  <div ng-show="showSidebar" class="sidebar">
    <div ui-view class="uiview"></div>
  </div>
</div>

CSS (LESS):

.container {
    display: flex;
}

.child {
    flex: auto;
}

.sidebar {
    width: 1000px; // This seems to act more like a max-width for the sidebar. The actual width matches the size of the ui-view.

    &.ng-hide-add, &.ng-hide-remove {
        transition: all ease .8s;
        overflow-x: hidden;
    }

    &.ng-hide {
        width: 0;
    }
}

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

Problem with Google+ Button Alignment

I arranged my social media buttons in a row - Twitter, Facebook & Google+. The issue is that the Google+ button is not aligning properly. It appears to be spaced out about 3 times further than the Twitter and Facebook buttons. I attempted adjusting the p ...

What steps can be taken to prevent a wrapper's CSS from affecting its enclosed elements?

My container div includes some opacity and auto height that I don't want to affect all elements within it. Is there a way to preserve the container's styles without impacting its contents? ...

AngularJS radio buttons are unable to be selected in a simplistic manner

I have implemented a dynamic list display using HTML radio buttons. Here is the code snippet: <html> <head> <script src="angular-v1.5.5.js"></script> </head> <body> <div ng-app="myApp" ng-controller=" ...

Condense categories

Hello there, I'm currently working on a table that contains different groups, and I am trying to figure out how to collapse categories within my table. Check out the Plunker here This is the HTML code snippet I am using: <table border=1> ...

Fixing the issue of list styles not displaying properly when using CSS3 columns in Webkit can be achieved by

example here: http://jsfiddle.net/R7GUZ/3/ I'm struggling to make the list-style property work in webkit for a parent OL that is styled with -webkit-column-count: 2; -moz-column-count: 2; column-count: 2; Is there a way to format an ordered list ...

MTG Life counter. Display fluctuations in count

I am currently working on a fun project creating an MTG (Magic The Gathering) life tracker, even though the code is quite messy. Despite its flaws, it still gets the job done. Click here to view the MTG life tracker https://i.stack.imgur.com/Su17J.png ...

What technique does Wordpress use to achieve this understated 3D appearance?

This unique effect that I've come across on various websites is quite subtle. I'm curious about how it achieves this effect. It seems like more than just a border, but also involves the empty space. ...

Storing data using Ionic Local Storage - easily save your $http database directly onto your

I have encountered a problem with the local storage in my Ionic app. The concept is simple - I want to save all the data from an SQL database to the device and then display it when there is no internet connection. Here is the code snippet where I fetch th ...

HTML: Attempting to extract the inner div from the outer div and relocate it outside of the outer div

I am attempting to extract an inner div from an outer div and relocate it outside of the outer div. https://i.stack.imgur.com/NSS7B.png <div class="vc_gitem-zone-mini"> <div class="vc_gitem_row.............."></div> <div> I Would ...

Exploring categories with AngularJS filtering

I dived into AngularJS today and embarked on creating a straightforward app featuring categories with items. The app showcases categories in a sidebar (aside.navigation) and displays all the items in the main view. My initial idea was to load all the item ...

What could be the reason my Bootstrap webpage is not optimized for mobile devices?

My website is currently hosted at "nateshmbhat.github.io". I have implemented mdboostrp's row and col for the structure of my website, but unfortunately, it is not very mobile-friendly as it displays a lot of unnecessary background space. If you woul ...

Controllers in Angular components being accessed

Trying to understand Angular 1 components has been my latest challenge. I created a simple component that was supposed to set a background color on initialization and then change the color when a button was clicked. Check out the code snippet below: < ...

Leverage the power of Bootstrap's col-push and col-pull

Here is the code snippet I am currently working with: <div class="col-md-9 col-md-offset-3"> <div class="row> <div class="col-sm-4 col-sm-push-4"></div> <div class="col-sm-8 col-sm-pull-8"></div> </div> ...

<div.content> </div.content> - Structure

I recall encountering this code before but I can't remember where: <div.main> // .... </div.main> <div.secondary> // .... </div.secondary> Could someone please clarify for me what this syntax is referred to as and what ...

Is there a way to customize the background color of the active list item class in Bootstrap 4?

Customizing Boostrap Code : <!-- Custom Sidebar --> <div class="bg-light border-right" id="sidebar-wrapper"> <div class="sidebar-heading"><strong><?= __('Admin Panel') ?></strong></div> <div class="li ...

What steps should I take to ensure that this modal remains persistent?

I am searching for a method to keep this modal persistent even after it appears. Currently, the user can easily close it by clicking outside of the div. <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title ...

React and Material UI collaboration causing layout problems

Seeking assistance with implementing React and Material UI in my project. My objective is to create a layout with 3 columns on desktop - one column with a radio button and label inline, and the other two columns containing select menus with option values. ...

How to customize font styles in AngularJS

I'm attempting to modify the font style of an element when a certain variable is true. Within my controller, I have a variable that retrieves its value. My objective is to adjust the font style depending on this value using ng-style. I've exhau ...

I am looking to customize the folder name dynamically in the flowFactoryProvider configuration so that I can subsequently send it to the upload.php file for the purpose of storing

Currently, I am utilizing the ng-flow plugin for uploading .zip files and it is functioning properly. However, I am looking to pass dynamic values like user_id and job_id in order to create dynamic folders where the uploaded files will be saved. The issue ...

Safari browser is experiencing issues with the custom file upload script

My custom upload script allows users to easily select images for upload by clicking or dragging them into the designated box. A preview of the chosen image should appear, and this functionality works smoothly in Firefox and Chrome. However, I've encou ...