gpt4 book ai didi

AngularJS 1.3 ng-repeat 动画移动项目不起作用

转载 作者:行者123 更新时间:2023-12-01 06:27:27 24 4
gpt4 key购买 nike

我有一个项目列表(div),当我单击其中任何一个时,我需要它们(带有动画)移动到列表的顶部。
但是,移动动画对我不起作用。
HTML 代码:

    <body ng-controller="myCtrl">
<div ng-init="items=[1,2,3,4,5,6,7,8,9]">
<div data-ng-repeat="item in items track by $index"
ng-click="move2Top($index)"
class="my-repeat-animation boxy">
{{item}}
</div>
</div>
</body>

Javascript Controller (包含用于将数组元素推送到数组顶部的数组原型(prototype)方法)
var myApp = angular.module("MyApp", ["ngAnimate"]);

myApp.controller('myCtrl', function($scope){
$scope.move2Top = function (idx) {
console.log('moving element ' + idx);
if (idx > 0)
$scope.items.moveToTop(idx);
};

Array.prototype.moveToTop = function(from) {
this.splice(0, 0, this.splice(from, 1)[0]);
};
});

和CSS:
.my-repeat-animation.ng-enter, 
.my-repeat-animation.ng-leave,
.my-repeat-animation.ng-move {
-webkit-transition: 0.5s linear all;
transition: 0.5s linear all;
position:relative;
}

.my-repeat-animation.ng-enter {
left:-10px;
opacity:0;
}
.my-repeat-animation.ng-enter.ng-enter-active {
left:0;
opacity:1;
}

.my-repeat-animation.ng-leave {
left:0;
opacity:1;
}
.my-repeat-animation.ng-leave.ng-leave-active {
left:-10px;
opacity:0;
}

.my-repeat-animation.ng-move {
opacity:0.5;
}
.my-repeat-animation.ng-move.ng-move-active {
opacity:1;
}

.boxy {
border: solid 1px;
margin: 3px;
padding: 3px;
border-radius: 4px;
width: 30px;
text-align: center;
}

请看示例:
http://plnkr.co/edit/asHtC5WOt9qnePyzPqk5?p=preview

动画 Action 根本行不通。

最佳答案

也许你可以引用堆栈上的这个问题。这可能与您想要实现的目标相似。
Animating ng-move in AngularJS ngRepeat is animating the wrong items

它并不完整,但它可能会给你一些想法或引导你走向正确的方向。

关于AngularJS 1.3 ng-repeat 动画移动项目不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26631553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com