<div class="box">
<p>CLICK ME TO BLUR OUT. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
// Animate an element by adding a class to it:
// Paramaters:
// anim: the class name to add
// time: animation duration (optional, fallsback to the class)
// cb: an optional callback function to happen once the animation ends
$.fn.animatecss = function(anim, time, cb) {
// If a time was specified add the transition speed to the element
// If not the animation defaults to the speed in the class
if (time) this.css('-webkit-transition', time / 1000 + 's');
// The class is the animation.
// We dont use any javascript animation
this.addClass(anim);
// Was a callback provided?
if ($.isFunction(cb)) {
// if a time was pecified wait that long then call the cb
// if not call the callback after 250 milliseconds
setTimeout(function() {
// Ensure that the element is available inside the callback.
$(this).each(cb);
}, (time) ? time : 250);
}
// Return the elements to allow chaining
return this;
};
$(document).ready(function() {
// When the user clicks an element with a class of box
$('.box').click(function() {
// Call the jQuery/zepto pluggin
$(this).animatecss('blur-out', 250, function() {
// The call back gets fired after the animation
console.log('callback');
});
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.