How can i insert slideUp and slideDown on angular way?

864 views
Skip to first unread message

Rodrigo Mendonça

unread,
Apr 17, 2014, 6:01:55 PM4/17/14
to ang...@googlegroups.com
I am new in angular and i think slideUp and slideDown is a good way to deliver user experience. But in angular i am not finding any solutions to do that. Im my project i have angular and jquery. 
How can i mix slideUp e slideDown from jQuery on angular way, with reusable code?

Thanks

--
Rodrigo Mendonça

Billy Figueroa

unread,
Apr 17, 2014, 9:30:46 PM4/17/14
to ang...@googlegroups.com
Not an answer but is there a "vote up" option for topics? This is a good question

I am using this in my code now and I just default back to jQuery.
   i.e. $('#login-box').slideUp('fast');

Luke Kende

unread,
Apr 18, 2014, 2:04:51 AM4/18/14
to ang...@googlegroups.com
You may be able to use ng-animate (have not messed with it yet, but it will want to use css transitions)... For jQuery methods, write a directive for any element you want to have this effect... something like:

<div slide-up="fast">Hello World</div>

.directive('slideUp',
function(){
return {
link: function(scope, element, attrs) {
    element.slideUp(attrs.slideUp)
}
}
}
)

This is an over simplified version. It will perform the animation as soon as the element is loaded... 

You probably need more some specific timing, but the directive is your friend for jQuery code.  If you want it to wait until some moment, like when it gets displayed, and a more generic directive for either direction, you can do something like this:

<div slide-animate="fast" direction="down">Hello World</div>

.directive('slideAnimate',
function(){
return {
link: function(scope, element, attrs) {
    scope.$watch(
function(){ return element.is(':visible') }, //watches for element to become visible
function(isShown){  
if (isShown){
switch (attrs.direction){
case 'up': element.slideUp(attrs.slideAnimate); break;
case 'down': element.slideDown(attrs.slideAnimate); break;
break;
}
}
)
}
}
}
)
Reply all
Reply to author
Forward
0 new messages