1

I've just started working on a project that requires me to learn AngularJS. What I'm trying to do is create two menus that slide into the screen, one from the left, one from the right. When they do this they push the content over.

Currently I can get one or the other to work, but not both. I realize this is because of the way that I'm defining the ng-class. I just can't quite conceptualize how to do it correctly.

<div ng-class="{true:'slide-left', false:''}[toggleSlide]" class="container">

    <div class="content">
        <button ng-click="toggleSlide = !toggleSlide" class="btn-left">From Left</button>
        <button ng-click="toggleSlide = !toggleSlide" class="btn-right">From Right</button>
    </div>

    <div class="slide-from-left">
        <p>Here is information that slides from off screen left.</p>
    </div>

    <div class="slide-from-right">
        <p>Here is information that slides from off screen right.</p>
    </div>
</div>
5
  • 1
    Its hard to understand what you're trying to do. Do you want both to be able to be displayed at the same time? Maybe you just need 2 variables - One for sliding left and out, the other for sliding right and out. Commented Apr 2, 2013 at 20:14
  • Can you post a Plunker? Commented Apr 2, 2013 at 21:03
  • Only one should be displaying at a time. If you've seen the functionality of Facebook app on an iPhone, it's very similar to the swipe left for your account menu, swipe right for the contacts on chat. I'll work on getting a jsfiddle up shortly. Commented Apr 2, 2013 at 21:14
  • Try and get a plunkr up or give some more info. For now I'll take a stab in the dark with this:<div ng-class="{'slide-left':toggleSlide, 'slide-right':!toggleSlide}" class="container"> Commented Apr 3, 2013 at 4:01
  • Justen, that worked great! I just didn't know what the syntax was to get multiple classes and variables into the ng-class. Cheers! Commented Apr 3, 2013 at 13:55

1 Answer 1

2

Set up the ng-class syntax like this for what you want:

<div ng-class="{'slide-left':toggleSlide, 'slide-right':!toggleSlide}" class="container">

Also, I'm guessing you were trying to adapt your code to something else you saw, so I'll offer something on that also. Here's an ng-class using ng-repeat's $index to dole out classes for even and odd:

ng-class="['even', 'odd'][$index % 2]"

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.