2

I am trying to show a <div> called settings when I click a button. It should fade in and then slide to the right. It fades in on the left side of the screen.

I have so far:

The HTML

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

and the link to call 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); } 

So I have it fading in but how do I now make it slide to the right by say 200px?

Also, I would like to be able to click anywhere other than the <div> itself to reverse the process.

1
  • @HunterTurner: tag removed, so not an issue any more :) Commented Dec 2, 2015 at 16:21

1 Answer 1

2

something like this:

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

in controller

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

and in css:

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

here is a working fiddle: http://jsfiddle.net/q5cqh9qj/

also, the reason for using two timeouts is, you can't run transition while you are changing display property (settings = true;)

Sign up to request clarification or add additional context in comments.

15 Comments

cheers for this - how would you recommend reversing the process. Add some kind of click handler to the whole of the right hand side of the page?
You could add a click handler to the document
Do I need to add another css rule to get the div to slide back again?
No, In settings CSS, set margin-left as 0, but then in slide CSS put an important along the margin left ( otherwise Id would override class selector)
but the settings css has a left:0
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.