Adjust the size of two divs in AngularJs as needed

I have two divs covering the entire page, each at 50% width. When the lower div is clicked, I want it to expand to cover the full screen, and return to its original size on click again. Here is an example:

See JQuery equivalent

$('.wrapper div.green').click(function() {
    $(this).toggleClass('go')
    if ($(this).hasClass('go')){
        $(this).animate({'height':'100%'},{
            duration:200,
            step:function(gox){
                var height = gox < 100 ? (100 - gox) / 1 : 0;
                $(this).siblings().css('height', height + "%"); 
            }
        })
    } else {
        $('.wrapper div').animate({'height':'50.00%'},200)
    }
});

Now I want to achieve this in AngularJS, but I'm new to it and encountering some challenges. I'm seeking guidance to help me move in the right direction. Here is what I've attempted so far:

See my AngularJs Attempt

All I want is a similar functionality as that of JQuery.

Answer №1

If you're looking for a solution inspired by your initial example, check out this implementation - http://jsfiddle.net/nz2vunLs/2/

This approach leverages CSS transitions along with the angular directives ngClass and ngClick. While it might not be the most elegant solution, it does get the job done effectively.

html

<div ng-app ng-controller="Controller" class="wrapper">
    <div ng-class="{min: greenFullscreen}" class="blue animation"></div>
    <div ng-class="{max: greenFullscreen}" ng-click="toggleGreen()" class="green animation"></div>
</div>

Controller

function Controller($scope) {
    $scope.greenFullscreen = false;

    $scope.toggleGreen = function() {
        $scope.greenFullscreen = !$scope.greenFullscreen;
    }
}

Additional CSS

.green.max {
    height: 100%;
}

.blue.min {
    height: 0%;
}

.animation {
    -webkit-transition: height 200ms;  
    -moz-transition: height 200ms;  
    -o-transition: height 200ms;  
    transition: height 200ms;
}

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

Transitioning from Jquery to vanilla JavaScript or transforming Jquery code into pseudo code

Struggling with a snippet of jQuery code here. While I have a good grasp on JavaScript, my knowledge of jQuery is somewhat limited. I am seeking assistance to analyze the following code in order to translate it into plain JavaScript or pseudo code that ca ...

"Encountering a Type Error in AngularJS due to the 'this

Is it possible to target the clicked element in Angular without using jQuery? $scope.hide = function() { this.querySelector('ul').style.display = 'none' }; Unfortunately, when I try to implement this, I encounter an error: Type ...

Display images quickly when the mouse is hovering

I am looking to create a function that will flash images when the mouse hovers over them and then stop flashing when the mouse moves away. However, I am experiencing an issue where "flash_imgs" is being called every time there is a mouse movement over the ...

You can eliminate the display flex property from the MuiCollapse-wrapper

Having trouble removing the display flex property from the MuiCollapse-wrapper, I did some research and found the rule name for the wrapper in this link https://material-ui.com/api/collapse/ I have been unsuccessful in overwriting the class name wrapper t ...

Encountering a 'popper.js is missing' error in Laravel while interacting with a Bootstrap 4 div that has the class 'input-group-prepend' on click

Upon clicking on an element enclosed by a div with the class input-group-prepend, I encountered the following error in the console: TypeError: popper is null app.js:50778:3 The click function works when I remove the surrounding div, but it's neces ...

Easily convert grams to kilograms with just a click of a button using JavaScript

Enter Grams(g): <input type="text" name="grams" id="grams"><br> <br> <button type="button" onclick="kiloConversion()">Convert to Kilogram</button> <p id="conversionResult"></p> ...

Error: Chrome is preventing an AJAX request

Hello everyone, I have been facing an interesting issue with my Ajax request. It seems to work perfectly fine in Internet Explorer, which is quite surprising. However, when I attempt to run the same code in Chrome, I encounter the following error: XMLHt ...

Controlling ever-changing routes using AngularJS

My AngularJS app (Angular v1) has a secure login system in place. Users who are not authenticated can only access the login page, forgotten password page, and cookie policy. I am utilizing ngRoute as shown below: $routeProvider .when('/login ...

Iterating through an array within an array in a React component

I am currently working on a basic React app where I have nested arrays and need to iterate over all the content. Here is my code snippet so far: {recipes.map((recipe) => ( <Recipe key={recipe.uid} title={r ...

The page is set to 100% width, yet the content is not completely occupying the space provided

I'm currently working on creating a responsive website using HTML, CSS, and Bootstrap 4. However, I am encountering difficulties in making my carousel width fill up the entire screen of Pixel 2 XL (landscape - w: 823px) and iPad (portrait - w: 768px). ...

Employing forward slashes as the template delimiter in JavaScript for HTML

let a = 1.10; let html = '<div>'\ '<strong>' + a + '</strong>\ //error here </div>'; console.log(html) Can you identify the issue in the code above? The intention is to insert a variab ...

Does the notion of "Execution context and the stack" only pertain to web browsers?

Does the concept of "Execution context and the stack" only apply to browsers, or is it also utilized in other environments such as NodeJS? I've crafted 2 statements but unsure if they are accurate: 1- "The environment for JavaScript is not solely the ...

React Sortable JS is causing the bootstrap grid style to disappear

As I work on developing a straightforward React application, my goal is to integrate React Sortable Js into my Bootstrap grid layout. However, when I enclose within <ReactSortable>, the grid layout no longer displays two boxes side by side in two ro ...

Methods for aligning navbar links vertically when incorporating an oversized icon

When utilizing Bootstrap 5 with Bootstrap Icons, I decided to increase the size of the icon using font-size:1.5rem;. However, this caused a disruption in the vertical alignment for the links (It works fine when the styling is removed and Full Page mode is ...

AngularJS basic webpage application halts code rendering

While working on an AngularJS tutorial on codeschool.com, I encountered a frustrating issue. Every time I refresh my browser to check my progress, the webpage ends up blank and refuses to load the code. I've restarted the tutorial from scratch twice, ...

The application within the Main Module is not being acknowledged by the other components within the module

I am facing an issue with my AngularJS application where the directive I created within the 'FormTest' module is not recognizing the variable 'app' even though it is defined within the same module. The error message I receive is TS2304 ...

I am unable to see the text field when I use element.text. What could be the reason for this

As I work on collecting online reviews using Selenium Chrome Webdriver, I've encountered a challenge with TripAdvisor. The reviews are truncated and require clicking a "More" button to view the complete text. Within the html code, there is a class cal ...

Angular5 Carousel: Spinning Your Web Pages in Style

I am in the process of creating an angular carousel slide. I found the necessary HTML and CSS code from the Bootstrap carousel example, but I am struggling with the JavaScript implementation from the site. Below is the HTML code in my app.component.html: ...

Issue with shadows on imported OBJ objects in Three.js when material is applied

After importing an obj using this load function: // triggered when the resource is loaded function ( obj ) { // For any meshes in the model, add our material. obj.traverse( function ( element ) { if ( element instance ...

Utilizing React Router Dom to Showcase Home Route from a Sub-Route

www.mywebsite.com www.mywebsite.com/ www.mywebsite.com/1 I need my website to show the same content for each of the links above. Currently, it is not displaying anything for www.mywebsite.com and www.mywebsite.com/ function App() { return ( <Rout ...