Stop the lower div from moving when the upper div is animated using ng-animate

I am facing an issue where the top div containing a title and a button fades away when clicked, revealing the bottom text. However, once the button disappears, the top div shrinks and the bottom div gets shifted upwards, leading to an undesirable layout.

How can I keep the top div fixed in height even after the button disappears?

I have thought of some solutions like placing an invisible element with the same height as the button to maintain space, but it doesn't feel elegant. Another option is setting a fixed height for the top div, but that may not be responsive on different screen sizes.

What would be a simple and elegant solution to this problem?

<div class="jumbotron">
    <h1><span class="hometitle">title</h1>
    <button class="btn btn-primary animate-show" type="button" ng-click="ctrl.showPoll = true" ng-show="!ctrl.showPoll">click here to show question</button>
</div>

    <div class="row marketing">
        <div class="col-lg-12">
            <form name="votForm" ng-show="ctrl.showPoll" ng-controller="frmCtrl as frm" ng-submit="frm.addVote(votForm.$valid)" novalidate>
                <p>question</p>
                <input ng-model="frm.vote" type="radio" name="myVote" value="1" required>op 1<br>
                <input ng-model="frm.vote" type="radio" name="myVote" value="2">op 2<br>
                <input ng-model="frm.vote" type="radio" name="myVote" value="3">op 3<br>
                <input ng-model="frm.vote" type="radio" name="myVote" value="4">op 4.<br>
                <input type="submit" value="submit" name="click me" >
                <div class="panel" ng-show="frm.showError">Please select an option before submitting </div>
            </form>
        </div>
    </div>

js

app.controller('votCtrl', ['$cookies', function($cookies){
    var showPoll = false;
    this.hasVoted = $cookies.iVoted || "nustiu";

}]);

css

.animate-show {
    opacity: 1;
}

.animate-show.ng-hide-add.ng-hide-add-active,
.animate-show.ng-hide-remove.ng-hide-remove-active {
    -webkit-transition: all linear 1s;
    transition: all linear 1s;
}

.animate-show.ng-hide {
    opacity: 0;
}

Answer №1

Avoid using the ng-hide class in your AngularJS code as it will completely conceal your button by applying display: none, which is not the desired outcome. Instead of using ng-show, consider implementing ng-class for better control.

<button class="btn btn-primary animate-fade" type="button" ng-click="ctrl.displayQuestion = true" ng-class="{'hidden-button-style': ctrl.displayQuestion}">Click here to reveal question</button>

To style this in CSS:

.hidden-button-style {
  opacity: 0;

  -webkit-transition: all linear 1s;
  -moz-transition: all linear 1s;
  -ms-transition: all linear 1s;
  -o-transition: all linear 1s;
  transition: all linear 1s;
}

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

Integrating VueJS seamlessly with your current Angular project

I am currently working on an angular application and I am interested in transitioning parts of it to a vueJS application. During development, all scripts are loaded in the main html file (in production mode they are bundled into app.js, but I would like t ...

Changing the color of a text box when it is disabled can be achieved through JavaScript

I'm facing an issue with the formatting of my HTML elements. Specifically, I have 2 combo boxes and one text box in which all 3 are disabled. However, when they are disabled, the background color of the text box does not match that of the combo boxes. ...

The issue of UI.Router injection failing for components in RequireJS and AngularJS 1.5

When I try to load components using the recommended method (Refer to step 3), I encounter this error: Error: Module name "angular-ui-router" has not been loaded yet for context: _. Use require([]) This is how my app module is defined: <script> v ...

Learn the marker area by following these instructions

At the moment, I am experimenting with Three.js, Aframe, and AR.js. I am following the example set by Jerome: https://github.com/jeromeetienne/AR.js/blob/master/three.js/examples/multi-markers/examples/player.html I have integrated his library into my sa ...

Tips on invoking the ('keyup') function within an AJAX request's success callback

I have been working on implementing a live search feature that is based on JSON data fetched through an AJAX call. Here is the code I have been using, but unfortunately, it is not functioning as expected. function returnVisitors(){ let output ...

"Exploring the versatility of using variables in jquery's .css

I’m facing an issue where I need the rotation of a div to be based on the value stored in "anVar." This is what I currently have: function something() { $('.class').css('-webkit-transform:rotate('anVar'deg)') } The desi ...

Comparing locale strings in Javascript using the valueOf method of the String prototype

I have the following code snippet: class MyClass { constructor(name) { this.name = name; } toString() { return this.name; } valueOf() { return this.name; } } const list = [new MyClass("b"), new MyClass("ä")]; list.sort(); ...

Ways to assign a placeholder to a dropdown menu

I'm trying to add a text placeholder to my selectbox, but all the options disappear when I try to do so. Can someone help me with this issue? Here is the code snippet I'm using: window.onload = function () { $('#slide').editableS ...

HTML/CSS: Maintain Hover-Over Pop Up Boxes in Position Until Another Element is Hovered Over

Seeking HTML code to maintain a hover-over pop-up box in position on an image map until another section of the image map is hovered over. For example, refer to my code below - when hovering over a country on the map, a pop-up box with information about a ...

Extract HTML data from the parent window of a URL without relying on an Internet Explorer browser - Tracking UPS information for multiple packages

Could I be heading in the wrong direction with my JavaScript code? I am new to using VBA for internet data retrieval and struggling to find a solution. Currently, I have a working function that utilizes IE.doc but it's slow and requires waiting for br ...

Element with a fixed position located inside a column in Bootstrap 4

Is there a way to keep a bar fixed at the bottom of the user's screen, but only within a specific column? Applying position:fixed; bottom:0; stretches the element across the entire screen, so how can I make the bar remain within the column boundaries? ...

value of previous checkbox selection

http://jsfiddle.net/thetylercox/gy8EQ/20/ $(':checkbox').change(function() { if (this.checked) { var lastChecked = $(this).prevAll(":checked:first"); if (this.value == lastChecked.val()) { alert("previous checke ...

Reading cached JSON value in a Node.js application

Recently, I embarked on creating a node.js application and reached a stage where I needed to retrieve a value from an updated JSON file. However, my attempts using the 'sleep' module to introduce a small delay were unsuccessful. I'm relativ ...

What is the procedure for attaching console.log to "l" in vue.js?

The code in main.js includes the following: window.l = function () { } try { window.l = console.log.bind(console) } catch (e) { } It functions properly in non-Vue applications. However, when trying to use it in a Vue action/method like this: l("test") ...

Internet Explorer 8 halts the progress of the loading animated GIF

When I call an animated loading gif image on an <asp:Button> click event in the client side code, the animation stops in IE8 while the server-side code is executing. This issue does not occur in Mozilla or other browsers. The animation works fine wh ...

How can I add a comma to a number input field when the numbers reach one thousand?

When setting the minimum and maximum prices of products, I encountered an issue where entering 10.000 displayed as 10000. To automatically add a decimal point to numbers and display it correctly as 10.000, I attempted the following solutions: <input typ ...

Ways to categorize subordinate rows in Datatables

In my table, I have implemented child rows that can be expanded/collapsed. However, I am facing an issue where the parent rows contain duplicate data. According to the official Datatables documentation, the child rows are referred to as secondary rows. In ...

Guide: Implementing Bulma Button Styles in React Components

Looking to integrate a Filter Buttons component into a To Do List Application. Specifically, I want to add four buttons for filtering tasks (All, Active, Completed, Important). Can someone guide me on how to incorporate Bulma CSS Rules with this react comp ...

Is it feasible to create rows within columns using Bootstrap framework?

Is it possible to achieve this layout using rows within columns with Bootstrap: https://i.sstatic.net/DC0f4.png I attempted the following without success: <div className="col-lg-3 col-12"> <div className="row"> ...

Tips for inserting a jQuery snippet into a universal file

Seeking some advice on integrating jQuery code into my JavaScript file, which is located at . The code snippet I am attempting to add looks like this: $(document).ready(function() { queue = new Object; queue.login = false; var $dialog = $ ...