Chaining fade in and slide effects on a div element

I am attempting to display a <div> named settings when a button is clicked. The intention is for it to fade in and then slide towards the right side of the screen, originating from the left side.

Progress so far:

The HTML

<div id="settings" ng-show="settings">

</div>

and the link to execute the showSettings() function:

<a href="#" ng-click="showSettings()"><i class="icon setting"></i></a>

The CSS

#settings {
    background:red;
    position:fixed;
    top:0;
    left:0;
    bottom:0;
    width:400px;
}

The Controller

$scope.showSettings = function(){
    $timeout(function() {
        $scope.settings = true;
    }, 250);     
}

Currently, I have achieved the fading effect, but how can I make the <div> slide to the right by a specified distance, like 200px?

Additionally, I would like the ability to click anywhere outside the <div> itself to reverse the process.

Answer №1

Here is an example:

Include ng-class="{slide:slideFlag}"

In your controller, add the following:

$scope.showSettings = function () {
$timeout(function () {
  $scope.settings = true;
  $timeout(function () {
    $scope.slideFlag = true;  
  }, 250);

}, 250);

For the CSS part, add the transition effect by using the following style:

.slide{
    transition: all 0.5s;
    margin-left:200px;
}

You can see a working demo here: http://jsfiddle.net/q5cqh9qj/

The reason for using two timeouts is that you cannot apply transitions while changing the display property (settings = true;)

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

Styling with CSS will keep your content centered on the page, while the background

I'm looking to create a layout with the following specifications: The content wrapper will have a fixed size and be centered: .content { width:960px; margin:0px auto; } My issue is how to implement the left-aligned background bar for the su ...

What is the process of displaying JSON response data in AngularJS?

I am attempting to retrieve URL information using get_meta_tags in Laravel and then display it in my AngularJS application. However, the issue is that the response is returned in the following format: Array ( [title] => Mercy Badshah Full HD [d ...

Utilize Bootstrap-Vue to ensure that an element expands to occupy the available space

In my Bootstrap-Vue application, I have set up the following hierarchy: <b-navbar.../> <b-container > <b-row align-v="center" style="min-height:100vh"> <b-col style="align-items:center"> <h1>404 Error&l ...

Ways to retrieve text from an input field using Protractor

Looking through the protractor documentation, I came across an interesting example: describe('by model', function() { it('should find an element by text input model', function() { var username = element(by.model('username&ap ...

Ways to prevent memory leaks in Angular applications

I have been searching for answers on whether my AngularJS code is causing a memory leak, but so far I haven't found any conclusive information. While I've come across articles discussing JavaScript memory leaks, they don't seem to address t ...

creating a randomized location within an HTML element using JavaScript

Trying to figure out how to randomly generate a position within an HTML div. I've come up with a JavaScript function that looks like this: function randomInRange(min, max) { return(Math.floor((Math.random() * (max - min) + 1) + min)); } My ...

AngularJS: Issue with $watch not triggering when changed in child scope

Here is the scenario I am facing: Within my parent scope, I have created an object named rule, which has an attribute called "keyword". A watcher is set on this keyword as follows: $scope.$watch("rule.keyword", function(newKeyword){...}); However, when t ...

What strategies can I use to include multiple spans within div elements without causing the code to become overly lengthy?

I'm working with 20 spans representing movie genres, each accompanied by another span that "closes" the genre when selected. The closing span has an .active class, similar to this example: My version currently looks like this: To achieve this, I hav ...

Enhance mix-blend mode or filtering effects in SCSS using an SVG component in VueJS

I am currently developing a fixed navbar at the top of a webpage with several SVGs inside anchor tags. I want the SVGs to appear black when displayed over lighter colored divs (other Vue components) and white when displayed over darker colored ones. The ba ...

AngularJS functions for PUT or POST requests may cease working if the parameter name is altered

In my controller class (ItensController.cs), I have 2 different methods: public void Put(int id, [FromBody]Item value) { } and [ActionName("UpdateItemFees")] [HttpPost] public void UpdateItemFees(int id, [FromBody]Item value) { } When making c ...

Difficulty in managing vertical overflow in a dynamically sized table using Bootstrap

I am facing an issue with the table-responsive class that is causing a scroll on the y-axis even though it is not specified in the CSS. Shown below is a screenshot of the problem, and I have also managed to replicate the bug: <div id="app"> <d ...

Troubleshooting: Magento checkout page keeps scrolling to the top

We are experiencing an issue where, during the one page checkout process, the next step is not automatically scrolling to the top of the page when it loads. After a user fills out all their billing information and clicks continue, the next step appears ha ...

Element does not cross both explicit and implicit columns

When working in a grid container with only 1 column and 1 row, if there is an implicit column in the first row, how can an element in the second row (as shown by the green column in the example) span across both the explicit and implicit columns? I appreci ...

What is the method to execute jQuery code after the completion of a fade out effect?

I am attempting to fade out a div upon click while also adjusting some CSS properties. The problem I am encountering is that the CSS properties change during the fade out transition, instead of after it has completed. I would like the values to change onc ...

Sophisticated approach to creating a dynamic form using ng-repeat

As a newcomer to AngularJS, I am facing the following issue: I need to loop through an array of 'attributes' containing keys that correspond to values stored in an Object. <div ng-repeat="key in attributes"> {{key}}: <input typ ...

Having Difficulty Positioning Tooltip Beside Input/Label Field

I have created a tooltip using HTML and CSS that appears when hovering over an image. However, I am encountering alignment issues when placing the image next to a textbox/input as it is not inline with the input box, likely due to some absolute positioning ...

Placing the ul tag within a div at the top of the div for proper alignment

I am facing an issue with my code where I cannot get the UL element to appear at the top of the div as it is a child element. <!doctype html> <html> <head> <title>xxx</title> </head> <body> <div id="page" style ...

Collapsed Grid System

Is it possible to create a CSS grid system that meets the following requirements: The grid should have arbitrary height (with consistent width) and when a grid overflows, it should stack vertically underneath the preceding grid, regardless of other grid ...

Retrieve the index of the item that has been selected in a dropdown list

<select ng-click="getIndex($index)" size="14" ng-model="playlist.fileSelected" ng-options="saveFile for saveFile in playlist.playlist"></select> When I try to access $index, it shows up as undefined. Is there a way to retrieve the index of the ...

The background is set and the vertical scrolling overflow is enabled

My website has an image set as the background, with a fixed position and overflow-y to allow scrolling. However, I have encountered an issue where the height of the image is causing problems on certain displays and resolutions. To temporarily fix this pro ...