Angularjs querySelector基于属性查找元素(Angularjs querySelector find element based on property)

编程入门 行业动态 更新时间:2024-10-07 13:25:20
Angularjs querySelector基于属性查找元素(Angularjs querySelector find element based on property)

我试图找到angularjs是否可以像下面这样做:

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

有人能帮我吗? 你可以在这里看到我的傻瓜 。

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.

最满意答案

编辑: 如果您不希望逐个指定,可以制定指令。 另外,删除控制器中不必要的代码。 在这里偷窃

.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); } }; });

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

我认为你正在以艰难的方式做到这一点。 我假设您不会使用ng-repeat,并且根据您的场景,您可以逐个具体说明动画延迟。

在这里偷窃

<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>

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>

更多推荐

本文发布于:2023-07-19 15:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1182570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   元素   querySelector   Angularjs   property

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!