Forked from leehsueh/angular-jquery-fade-slide-directive.js
Created
December 28, 2012 21:35
-
-
Save fcoury/4402158 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('myApp', []); | |
app.directive('jqShowEffect', ['$timeout', function($timeout) { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
// configure options | |
var passedOptions = scope.$eval(attrs.jqOptions); | |
// defaults | |
var options = { | |
type: 'fade', // or 'slide' | |
duration: 200, | |
delay: 0, | |
hideImmediately: false, // if true, will hide without effects or duration | |
callback: null | |
}; | |
$.extend(options, passedOptions); | |
var type = options.type; | |
var duration = options.duration; | |
var callback = options.callback; | |
var delay = options.delay; | |
var hideImmediately = options.hideImmediately; | |
// watch the trigger | |
var jqElm = $(element); | |
scope.$watch(attrs.jqShowEffect, function(value) { | |
if (hideImmediately && !value) { | |
jqElm.hide(0, callback); | |
} else { | |
$timeout(function() { | |
if (type == 'fade') { | |
value ? jqElm.fadeIn(duration, callback) : jqElm.fadeOut(duration, callback); | |
} else if (type == 'slide') { | |
value ? jqElm.slideDown(duration, callback) : jqElm.slideUp(duration, callback); | |
} else { | |
value ? jqElm.show(duration, callback) : jqElm.hide(duration, callback); | |
} | |
}, delay); | |
} | |
}); | |
} | |
} | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div jq-show-effect="whatever you use for ng-show" jq-options="{type:'fade', duration:200, delay:200, hideImmediately: true}">Content</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment