0

I tried to find if angularjs can do like below:

angular.element(document.querySelector('.content-here').find('div.offsetTop=8');

Can someone help me? You can see my plunker here.

8
  • what do you want to find in your plunker? there is no div with class offsetTop in your plunker. there's a text node with content that contains {"localName":"div","offsetTop":8}. did you intend to create DOM nodes based on the enries of $scope.show array? Commented Nov 26, 2016 at 11:13
  • I want to allocate class animated fadeInLeft in each element with different respective delays. $scope.show just show the property I got from my variable elementObj. Are you clear? Sorry for bad english. Commented Nov 26, 2016 at 11:24
  • in each element - what element? Commented Nov 26, 2016 at 11:33
  • All elements contained in .content-here class. In my case all the divs including image. Commented Nov 26, 2016 at 11:37
  • angular.element(document.querySelector('.content-here'))[0]will work for you. Commented Nov 26, 2016 at 11:42

1 Answer 1

1

Edited:
You could make a directive if you do not wish to specify one by one. Also, remove the unecessary code in the controller. Plunker here

  .directive('animateFromLeft', function($compile) {
      return {
        restrict: 'AE',
        link: function(scope, elem, attr) {
          var children = elem.children();
          children.addClass('animated fadeInLeft');

          var animationDelay = 0;
          for(var i = 0; i < children.length; i++) {
            children[i].style.animationDelay = animationDelay.toString() + 's';
            animationDelay += 1;
          }

          $compile(elem)(scope);
        }
      };
    });

========================================================================

I think you are doing it in hard way. I assume that you will not be using ng-repeat and based on your scenario you can specific the animation delay one by one.

Plunker here

<div class="content-here">
      <div class="animated fadeInLeft" style="animation-delay: 0s">1</div>
      <div class="animated fadeInLeft" style="animation-delay: 1s">2</div>
      <img class="animated fadeInLeft" style="animation-delay: 2s" width="100px" src="https://staticdelivery.nexusmods.com/mods/110/images/74627-0-1459502036.jpg" />
      <div class="animated fadeInLeft" style="animation-delay: 3s">3</div>
      <div class="animated fadeInLeft" style="animation-delay: 4s">4</div>
    </div>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. I need to use that way since I did not want to add manually the class. Let the querySelector find and addClass from there.
Brilliant! Thank you very much for your nice codes!.

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.