Dynamic sliding box jumps instead of simply fading in/out

My app features both a navigation bar and a sub-navigation bar. Within the sub-navigation bar, users can click on a button that triggers the appearance of another sub-bar while hiding the original one.

The new sub-bar should smoothly slide out from behind the main bar to conceal the second bar.

However, there are a couple of issues:

  1. When the third bar appears, it bounces instead of sliding in seamlessly
  2. When the third bar disappears, it simply vanishes without sliding back up as expected

I've attempted adjusting the top property to address this problem, but it hasn't resolved the issue.

You can view the code snippet below or access it directly on jsfiddle

angular.module('myapp.controllers', []);

var app = angular.module('myapp', ['myapp.controllers', 'ngAnimate']);

angular.module('myapp.controllers').controller("BarController", function ($scope) {
    $scope.showActionsBar = false;

    $scope.cancelAction = function () {
        $scope.showActionsBar = false;
    }

    $scope.click = function () {
        $scope.showActionsBar = true;
    }
});
.navbar-deploy {
    background-color: red;
    border: solid transparent;
}

.third, .sub-navbar-fixed {
    background-color: black;
    width: 100%;
    height:60px;
    padding-top: 18px;
    margin-bottom: 0px;
    z-index: 1000;
    color: white;
}

.actions-bar {
    top: 40px;
    background-color: yellow;
    position: fixed;
    padding-left: 0px;
    z-index: 1001;
}

.sub-bar {
    padding-top: 40px;
}

.third-in, .third-out {
    -webkit-transition:all ease-out 0.3s;
    -moz-transition:all ease-out 0.3s;
    -ms-transition:all ease-out 0.3s;
    -o-transition:all ease-out 0.3s;
    transition:all ease-out 0.3s;
    -webkit-backface-visibility: hidden;
}

.third-in.myhidden-remove, .third-out.myhidden-add.myhidden-add-active {
    display: block !important;
    top: -2000px;
    z-index: 0;
}

.third-out.myhidden-add, .third-in.myhidden-remove.myhidden-remove-active {
    display: block !important;
    top: -80px;
    z-index: 1001;
}

.myhidden {
    visibility: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.12.1/ui-bootstrap-tpls.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-animate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui/0.4.0/angular-ui.min.js"></script>
<div ng-app="myapp">
    <div ng-controller="BarController">
        <div class="navbar-deploy navbar navbar-default navbar-fixed-top">
            <div class= "container-fluid">
                <div class="col-lg-2">First Toolbar</div>
            </div>
        </div>
        <div class="sub-bar">
            <div class="sub-navbar-fixed" ng-cloak>
                <div class="container-fluid">
                    <span>
                        <a ng-click="click()"><span> Second Toolbar</span>
                        </a>
                        <div class="actions-bar third third-in third-out" ng-cloak ng-class="{'myhidden': !showActionsBar}">
                            <div class="container-fluid form-group"> <span class="col-lg-10">
                            <div class="col-lg-2 col-lg-offset-1">
                                    <a ng-click="cancelAction()">Back</a>
                            </div>
                    </span>

                        </div>
                    </div>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

Answer №1

Give this a shot:

.mystyle{ position:absolute; left:-3000px; }

Answer №2

Frankly speaking, I have a hunch about why the "bounce" effect is happening. It seems like your yellow container is initially hidden and positioned at its final visible spot. As a result, during the animation, the menu jumps up before moving down.

A possible solution could involve positioning the yellow container underneath the black menu when it's not visible. However, it might get tricky due to the convoluted structure of your HTML where the container is nested inside a span within the red menu.

If you're open to revising your code, recreating the menu effect from scratch using basic CSS, HTML, and jQuery could be a cleaner approach. Here's a simplified implementation that avoids relying on z-index:

<div class="header">
    <div class="header-bot">
        <span class="show">second toolbar</span>
    </div>
    <div class="header-extra">
        <span class="hide">back</span>   
    </div>
    <div class="header-top">
        <span>first toolbar</span>
    </div>
</div>

This accompanying CSS sets the groundwork for the desired layout:

body {margin:0;padding:0;}
span {color:#fff;}
.header {
    width:100%;
    position:fixed;
    top:0;
}
.header-top {
    background-color:black;
    height:50px;
    position:absolute;
    top:0px;
    width:100%;
}
.header-bot {
    background-color:red;
    height:50px;
    position:absolute;
    top:50px;
    width:100%;
}
.header-extra {
    background-color:yellow;
    height:50px;
    position:absolute;
    top:0;
    width:100%;
    transition: all 0.3s ease;
}
.down {
    top:50px;
}
.hide {color:#000;}

Lastly, this minimal jQuery script toggles the 'down' class based on button clicks:

$(document).ready(function () {
            $('.show').click(function () {
                $('.header-extra').addClass("down"); 
            });
            $('.hide').click(function () {
                $('.header-extra').removeClass("down"); 
            });
        });  

By following this approach, you can achieve a similar menu effect while maintaining a more organized code structure. Feel free to check out the provided JSFiddle link for a live demo.

FIDDLE

Answer №3

To stop the bouncing effect, simply delete the third-in and third-out classes from the div element.

<div class="actions-bar third " ng-cloak ng-class="{'myhidden': !showActionsBar}">
                        <div class="container-fluid form-group"> <span class="col-lg-10">
                        <div class="col-lg-2 col-lg-offset-1">
                                <a ng-click="cancelAction()">Back</a>
                        </div>
                </span>

                    </div>
                </div>

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

Changing an Array into JSON format using AngularJS

I am attempting to switch from a dropdown to a multiselect dropdown. <select name="molecularMethod" class="form-control" ng-model="request.molecularMethod" multiple> It is functioning properly. However, when items are selected, it generates an arra ...

Utilize the :not() and :hover selectors in Less when styling with CSS

Some of my elements have a specific class called .option, while others also have an additional class named .selected. I want to add some style definition for the :hover state on the .option elements, but only for those without the .selected class. I' ...

Responsive HTML5 audio player adjusts size when viewed on mobile devices

I am facing a challenge with an HTML5 Audio player. It looks fine on desktop but behaves strangely on mobile devices. While the width remains intact, it repositions itself and floats over the element it is contained within. How can I prevent this repositio ...

Combine angular ui router templates using grunt into a single file

Currently, I am working on an angular-ui-router project that consists of 150 files scattered all over. My goal is to create a grunt task that will merge all these files into a single index.html file structured like this: <script type="text/ng-template" ...

utilize jquery ajax to input various data

I am attempting to include multiple data in a jQuery ajax call. However, my current implementation is not working as expected. The data fetched is taken from the following span: <span id="<?php echo $tutorial_id; ?>" modes="<?php echo $modese ...

Embedding content within a toggle slider

As a beginner in CSS, I have a simple question that needs addressing. I am unsure which class to begin with for my task. The goal is to insert text (specifically, two digits) neatly inside toggle buttons (the slider that moves and appears white). I am u ...

Having trouble with implementing Nested routes in Vuejs?

main.js import Vue from "vue"; import App from "./App.vue"; import VueRouter from "vue-router"; import HelloWorld from "./components/HelloWorld"; import User from " ...

What are the steps to implement timer control in Ajax using JavaScript?

Hello, I have been trying to establish communication with the server through my application. To achieve this, I made a call to the webservice using AJAX. Now, I am looking to incorporate a time interval in AJAX. Can anyone kindly provide guidance on how ...

Check out the selected values in Ionic 3

I am trying to retrieve all the checked values from a checkbox list in an Ionic3 app when clicked. Below is the code snippet: <ion-content padding> <ion-list> <ion-item *ngFor="let item of items; let i= index"> <ion-label>{{i ...

Creating a Navigation Bar using the Flexbox property

As a beginner, I attempted to create a navbar using flex but did not achieve the desired outcome. My goal is to have: Logo Home About Services Contact * { margin: 0; padding: 0; font-family: ...

Angular 8 fails to retain data upon page refresh

I have a property called "isAdmin" which is a boolean. It determines whether the user is logged in as an admin or a regular user. I'm using .net core 2.2 for the backend and Postgre for the database. Everything works fine, but when I refresh the page, ...

Is it beneficial to rotate an image before presenting it?

I am looking for a way to display a landscape image in portrait orientation within a 2-panel view without altering the original file. The challenge I am facing is that the image size is set before rotation, causing spacing issues with DOM elements. Is ther ...

Breaking down and analyzing XML information

I have data that I need to retrieve from an XML file, split the result, parse it, and display it in an HTML element. Here is a snippet of the XML file: <Root> <Foo> <Bar> <BarType>Green</BarType> &l ...

Run a Javascript function when the expected event fails to happen

I currently have this setup: <input type="text" name="field1" onblur="numericField(this);" /> However, I am struggling to figure out how to execute the numericField() function for the element before the form is submitted. I attempted using document ...

When the limit is set to 1, the processing time is 1ms. If the limit is greater than 1, the processing time jumps to

Here is the MongoDB Native Driver query being used: mo.post.find({_us:_us, utc:{$lte:utc}},{ fields:{geo:0, bin:0, flg:0, mod:0, edt:0}, hint:{_us:1, utc:-1}, sort:{utc:-1}, limit:X, explain:true }).toArray(function(err, result){ ...

Discovering the most concise string within the array

I've been working on a JavaScript program function that is supposed to return the smallest string in an array, but I keep encountering an error whenever I run it. Below is the code I have written: function findShortestWordAmongMixedElements(arr) { ...

What factors cause variations in script behavior related to the DOM across different browsers?

When looking at the code below, it's evident that its behavior can vary depending on the browser being used. It appears that there are instances where the DOM is not fully loaded despite using $(document).ready or similar checks. In Firefox, the "els ...

Current page with animated CSS3 menus

I found a cool menu example on this webpage: http://tympanus.net/Tutorials/CreativeCSS3AnimationMenus/index10.html. I want to modify it so that the current page's menu item has a different color from the others. For example, when I'm on the home ...

When utilizing "column-count" with "display: flex", both Firefox and IE will only render a single column

I am struggling to achieve a two-column layout with nested columns inside each one. The code I used looks great on Chrome and Safari, but on Firefox and IE, it only displays in a single column: What mistake am I making here? .two-columns { column-cou ...

Having trouble receiving a JSON array after making an Ajax request

I have read through previous posts on this issue, but I still can't seem to figure it out. Hopefully, someone here can help me solve this problem. My challenge lies in retrieving an array, which I have encoded in json, from a PHP script and passing i ...