<p>
Click on any button to toggle it's dialog. Each of them has a different message, but the Exit time is set to 2.5 seconds for each. To close it earlier click on it!
</p>
<button data-toggle="dialog" title="I'm a dialog box!">Click me</button>
<button data-toggle="dialog" title="I'm here too!">Click me</button>
<button data-toggle="dialog" title="I'm self dismissable!">Click me</button>
// get dialog toggler btn
var dialogToggle = $('[data-toggle="dialog"]');
// set markup for dialog
var dialog = "<div class='dialog'></div>";
//set variables for timed animations
var animateDialog, removeDialog;
// show dialog on button click
dialogToggle.on('click', function() {
// clear timers to ensure propper timing upon new click
clearTimeout(animateDialog);
clearTimeout(removeDialog);
// get text to be displayed on clicked dialog
var text = $(this).attr('title');
// remove any dialogs in the page
$('body .dialog').addClass('out').remove();
// append dialog markup to body
$('body').append(dialog);
// find added dialog and add it's text
$('.dialog').text(text);
// set animation out timer
animateDialog = setTimeout(animate, 2500);
// set removal from dom timer
removeDialog = setTimeout(remove, 3000);
});
// enable dismissability of dialog upon click
$(document).on('click', '.dialog', function() {
// add animation out class
$('body .dialog').addClass('out');
// clear timers
clearTimeout(removeDialog);
// remove from dom
removeDialog = setTimeout(remove, 600);
});
// function to add class for animating out
function animate() {
$('.dialog').addClass('out');
}
// function to remove dialog from dom
function remove() {
$('.dialog').remove();
}
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.