The content is stationary as the side menu slides open and closed

I have successfully implemented a sliding side menu in my angularjs+bootstrap3 app using CSS. However, I am facing an issue where the content on the right side does not follow the menu when it slides out of view.

Here is the desired effect that I am aiming for:

In the example provided, clicking the button with three horizontal lines toggles the menu to the side and moves the content along with it towards the left.

style.css

.sidebart {
    -moz-transition: left .1s;
    -webkit-transition: left .1s;
    -o-transition: left .1s;
    transition: left .1s;
    width: 210px;
    height:100%;
    background-color:#2a3542;
    position: absolute;
    top: 0px;
    bottom: 0px;
    left: 0px;
}

.slide-outt {
    -moz-transition: left 1s;
    -webkit-transition: left 1s;
    -o-transition: left 1s;
    transition: left 1s;
    left: -210px;

}

partial.html

<div ng-controller="myCtrl">

<button class="btn btn-default collapse-button" ng-click="click()">Toggle collapse</button>
 <div id="sidebar" class="sidebart" ng-class="{'slide-outt':boolChangeClass}">
<!-- sidebar menu start-->
<ul class="sidebar-menu" id="nav-accordion">
<li>
                                  <a href="#/customer">
                                      <i class="fa fa-user"></i>
                                      <span>Customers</span>
                                  </a>
                              </li>
           <li>
                                  <a href="#/order">
                                      <i class="fa fa-tasks"></i>
                                      <span>Orders</span>
                                  </a>
                              </li
            </div>

controller.js

function myCtrl($scope) {
    $scope.click = function() {
        $scope.boolChangeClass = !$scope.boolChangeClass;
        //$scope.$apply();
    };
}

Answer №1

Upon analyzing the provided example link, it is crucial to highlight two key classes that play a significant role in the functionality not explicitly mentioned in your query:

.main-content-wrapper {
    margin-left: 240px;
    ...
    transition: all .3s ease-in-out;
}
.main-content-toggle-left {
    margin-left: 0;
}

The margin-left: 240px property within .main-content-wrapper shifts the main content towards the right side to make room for the sidebar. When the sidebar is closed, .main-content-toggle-left comes into play by adjusting the margin through margin-left: 0;, moving the main content back snugly against the left edge of the screen. The inclusion of transition: all .3s ease-in-out; ensures that both the sidebar and main content move synchronously.

Your implementation involves utilizing left: -210px in the .slide-outt class rather than margins, with the assumption that when the sidebar slides away, the main content will follow suit. However, due to the usage of position: absolute on the sidebar, it does not impact the layout of other elements, hence failing to influence the page's flow upon applying left: -210px.

To synchronize the movement of your main content with the sidebar, implement a transition on the main content that mirrors its lateral shift. The specific styling modifications required heavily depend on the existing positioning of your main content, with potential options like altering its left value akin to the sidebar or resorting to margins.

For an extensive understanding, refer to the MDN documentation on position, left, and margin. It is imperative to note that attributes such as left and margin yield varied outcomes based on the element's positioning type.

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

What is the best way to create an associative array using jQuery and then send it through AJAX to be parsed by PHP?

Is there a way to create an associative array in jQuery and send it via ajax to a php page for processing? Here is an example of what I am trying to achieve... // jQuery if($something == true) { data[alt] = $(this).attr('alt'); data[sr ...

Using Jquery to retrieve the window size and dynamically apply it to a div's CSS, adjusting it accordingly when the

Hey there! I'm trying to create a full-screen div, but unfortunately CSS doesn't seem to do the trick in this case. JavaScript/jQuery is my only option. My plan is to dynamically set the size of the div based on the browser window's dimensi ...

Generate listview items containing anchor tags automatically

I am currently developing a web application using Jquery Mobile. After retrieving data from a webservice function, I am utilizing an ajax call to display this data on my webpage. $('[data-role=page]').on('pageshow', function () { var u ...

What steps do I need to take to transform this HTML snippet into a Bootstrap design

Looking to convert the table below into bootstrap rows and columns. I'm not very familiar with bootstrap, but would like to give it a try. Any guidance on where to start would be greatly appreciated. Thank you for your help! <div id="section1"> ...

Displaying and Concealing Divisions

My journey to showing/hiding divs began with piecing together a series of questions: $(document).ready(function(){ $('.box').hide(); $('#categories').onMouseOver(function() { $('.box').hide(); $('#div' + ...

The issue arising where the callback function fails to execute after making an AJAX POST request

Within my function, I have an AJAX call that I want to make reusable. When the AJAX call is successful, I need to callback a function. var ajaxPostCall = function(data , url ,callback){ // Return the $.ajax promise $.ajax({ data: data, dataType: ...

Looking to transfer JSON data between JavaScript and Java code

I am dealing with a JSON string within my JavaScript code and I want to pass this information to a Java class. Can I simply use a regular Java class for this task or is it necessary to implement a servlet? Furthermore, I am curious about the process of pa ...

Create a custom loading spinner for a jQuery AJAX request

How can I add a loading indicator to my Bootstrap modal that is launched from a link? Currently, there is a 3-second delay while the AJAX query fetches data from the database. Does Twitter Bootstrap have built-in functionality for this? UPDATE: Modified J ...

Create custom styles for Android applications using CSS or themes programmatically

As I work on developing an application, I am interested in implementing a unique approach... To retrieve a CSS file from the server and apply it to the activity layout. To create a string file for styling or theming and integrating it into the layout. I ...

How can I use jQuery to set the color of every other row in a

I'm facing an issue where I want to use jQuery to set the color of alternate rows in an HTML table. However, every time I add a new row, the color of the entire table switches. Below is the JavaScript code snippet that I am utilizing: var alternate = ...

Attempting to update information in JSON using AJAX and PHP

I am attempting to update key values in a JSON object using PHP, AJAX, and JavaScript to display the new values. Here is an example of my JSON database that needs to be modified: "answer01count": "1", "answer02count": "2", "answer03count": " ...

The curly braces in AngularJS are not resolving as expected, however, the ng-bind directive is functioning properly

I'm currently working on a Django application and utilizing AngularJS for my frontend. I have a straightforward piece of code that looks like this: <div class="vert-carousel" ng-controller="PrizeController"> <div class="gallery-cell" n ...

Guide on integrating a php script into a react application

I'm currently in the process of setting up a functional contact form on my website by following the guidance provided in this article link. However, the tutorial includes a php script to manage the post data, and I am using create-react-app and unsure ...

Optimizing the selection and deselection of checkboxes using JQuery with X checkboxes in mind

If I have a set of 'X' checkboxes (any input elements) in a form and "M" option selection indexes ("M" less than or equal to "X"), how can I efficiently select the "M" option indexes/values and deselect the remaining checkboxes? For example, if ...

Modify the parent scope variable within an Angular directive that contains an isolated scope

Here is a directive implementation: <some-directive key="123"></some-directive> This directive code looks like this: angular.module('app').directive('someDirective', ['someFactory', '$compile', '$ ...

Using CURL in PHP to make a post request on a form

this is the form: <textarea name="message" id="messageContent" rows="18" wrap="virtual" tabindex="2"></textarea> <span id="formSubmit"> <a href="#" class="formSubmit" tabindex="3"> <img src="/clear.gif" class="master-sprite ...

Tips for creating a table that fills the height of its parent div without surpassing it

Issue: I am facing a challenge with making a <table> element fill 100% of its container's height dynamically, without going over the limit. Context: When the height of the <table> surpasses that of the container, I want the ability to s ...

How Vue.JS can efficiently send computed values from the parent component to the child component using props

In my demo app, I have a scenario where I am generating a random number through a computed property in the root component. This random value is then passed to a child component using props. However, I am struggling to find the correct approach to update t ...

Reorder data in an array using a specific field in AngularJS

I am working with an array that looks like this: [Object,Object,Object]; Each object in the array has a property named "rate". I need to sort these objects based on their rate property. In my JavaScript, I have a variable called $scope.restaurants.data, ...

The ajax call is returning null parameters

I've defined a method within ASP.NET MVC as follows: public PartialViewResult SaveUpdateVariants(string TitleEn, string TitleAr, int ItemID, List<ItemVariant> data) { } This method is being invoked through an AJAX call like so: $.ajax({ ...