Max*_*kyi 11 javascript angularjs
我正在制作div.它具有以下定义:
<div ng-show="showTranslations" ng-swipe-right="showTranslationsBlock=false">...</div>
Run Code Online (Sandbox Code Playgroud)
我有以下css定义:
div.ng-hide {
transition: 0.5s linear opacity;
opacity: 0;
}
div.ng-hide-add,
div.ng-hide-remove {
/* this needs to be here to make it visible during the animation
since the .ng-hide class is already on the element rendering
it as hidden. */
display:block!important;
}
Run Code Online (Sandbox Code Playgroud)
这取自本教程.动画有效.但:
.ng-hide-add和.ng-hide-remove?ng-hide-add-active和ng-hide-remove-active?尽管我添加了以下css规则,但为什么在div变得可见时没有转换:
div.ng-hide-remove {
opacity: 1;
}
UPDATE
animation frame (this performs a reflow).我的理解是否正确?为什么animation frame会在那里提到?ng-hide-add-active,也没有ng-hide-remove-active添加.UPDATE1
我已经探索了Angular的源代码,并为该ng-hide指令找到了以下内容:
var ngHideDirective = ['$animate', function($animate) {
return function(scope, element, attr) {
scope.$watch(attr.ngHide, function ngHideWatchAction(value){
$animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide');
});
};
}];
Run Code Online (Sandbox Code Playgroud)
据我所知,ng-hide该类是通过动画服务添加的.但是,如果我不使用动画和$animate服务,会发生什么?考虑到上面的代码以及如何添加ng-hide类,Angular将如何处理这种情况?或者这$animate.addClass()只是添加回调addClass事件?

pix*_*its 16
将你的CSS转换放在ng-hide-remove,ng-hide-remove-active上:
div.ng-hide-remove {
transition: 0.5s linear opacity;
opacity: 0;
}
div.ng-hide-remove-active {
opacity: 1;
}
Run Code Online (Sandbox Code Playgroud)
同样,对于ng-hide-add和ng-hide-add-active:
div.ng-hide-add {
transition: 0.5s linear opacity;
opacity: 1;
}
div.ng-hide-add-active {
opacity: 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9107 次 |
| 最近记录: |