[英]Angular.JS delay route change for do animation
我正在使用Semantic UI作為前端框架。 在其中,我有一個Javascript函數用於創建一些過渡,更多信息在這里 。
我想用它來在Angular.JS中創建路徑更改動畫。 我試着這樣做:
app.run(['$location', '$rootScope', function($location, $rootScope) {
$rootScope.$on('$routeChangeStart', function (event, next) {
$("#main").transition('fade up', '300ms');
});
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$("#main").transition('fade down', '300ms');
});
}])
#main
是DOM元素,其中是我的ng-view。 但它並不適用,因為路線變化太快了。 所以,我的問題是,我可以延遲路線改變? 或者可能是更好的解決方案?
我認為考慮延遲路線改變並不是一個好主意,因為如果路線快速連續變化,你可能會遇到問題。
然而,Angular已經內置了對動畫的支持,包括javascript驅動的轉換,如(可能)來自Semantic UI的轉換。 有相當多的信息
但我認為你需要的是
Angular將在輸入視圖時執行什么操作,它將調用“enter”轉換,並在調用傳遞的“done”函數后進行清理。
myApp.animation('.my-animated-view', function() {
return {
enter : function(element, done) {
//node the done method here as the 3rd param
$(element).transition('fade up', '300ms', done);
return function(cancelled) {
/* this (optional) function is called when the animation is complete
or when the animation has been cancelled (which is when
another animation is started on the same element while the
current animation is still in progress). */
if(cancelled) {
// Something here to stop?
}
}
},
leave : function(element, done) { done(); },
move : function(element, done) { done(); },
beforeAddClass : function(element, className, done) { done(); },
addClass : function(element, className, done) { done(); },
beforeRemoveClass : function(element, className, done) { done(); },
removeClass : function(element, className, done) { done(); },
allowCancel : function(element, event, className) {}
};
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.