2013-04-10 98 views
3

我試圖實現使用JS演示的例子,但出現了一些問題NG-開關...我可以看到,在DOM中添加新的元素,但NG-開關沒有刪除不需要的DIV。你可以請幫助...角NG-動畫工作不正常

這裏是Fiddle...

var ngModule = angular.module('myApp', []); 
ngModule.animation('js-wave-enter', function() { 
return { 
    setup: function (element) { 
     //prepare the element for animation 
     element.css({ 'position': 'absolute', 'left': '100%' }); 
    }, 
    start: function (element, done, memo) { 
     //start the animation 
     element.animate({ 'left': 0 }, function() { 
      //call when the animation is complete 
      done(); 
     }); 
    } 
} 
}); 

ngModule.animation('js-wave-leave', function() { 
return { 
    setup: function (element) { 
     //prepare the element for animation 
     element.css({'position': 'absolute', 'left': 0  });   
    }, 
    start: function (element, done, memo) { 
     //start the animation 
     element.animate({ 'left': '-100%'  }, function() { 
      //call when the animation is complete 
      done(); 
     }); 
    } 
} 
}); 

回答

2

jQLite不包括動畫()方法。在包含Angular之前,您需要包含jQuery,並且您的代碼可以正常工作。所以剛纔的腳本代碼,包括AngularJS之前添加以下內容:

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 

Updated jsFiddle

+0

由於一噸..還有另外一個問題,如果ü可以幫助..似乎'element.css(「高度」 )'不工作,如果我刪除jquery ...行11,12 [fiddle ..](http://jsfiddle.net/LFFav/14/)..任何想法爲什麼..? – Bhavesh 2013-04-10 22:39:32

+0

如果檢查DOM,你會看到兩件事情:1)你的第一次NG-開關DIV的高度爲0,但對於第二個是20像素。 2)當CSS動畫短時間運行時,會顯示'true'和'false'DIV。在JS動畫中從未發生過。所以我相信錯誤在於這些矛盾之一(或兩者)的某處。 – 2013-04-10 23:27:48

+0

有一個在這裏深入的文章一個很好的涵蓋所有新的動畫鉤在這裏1.1.4:http://www.yearofmoo.com/2013/04/animation-in-angularjs.html – 2013-05-20 14:54:07