Skip to content

Instantly share code, notes, and snippets.

@meglio
Created January 31, 2014 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meglio/8730959 to your computer and use it in GitHub Desktop.
Save meglio/8730959 to your computer and use it in GitHub Desktop.
Creates a nice caption which disappears with animation like on this video: http://www.screenr.com/4xmH - useful for "Saved" notifications over "Save" buttons etc.
.action-success {
position: absolute;
z-index: 1000;
color: green;
border: 1px dashed green;
background-color: rgba(255,255,255,0.5);
font-size: 14px;
padding: 2px 4px;
border-radius: 8px;
text-align: center;
display: block;
visibility: hidden;
}
function popoverActionSuccess(targetElement, message) {
var div = $('<div>').addClass('action-success').text(message),
targetOffset = targetElement.offset(),
top = (targetOffset.top - 10) + 'px'
console.log('Outer width: ' + div.outerWidth())
// Append first to retrieve dimensions
div.appendTo($('body'))
var left = (targetOffset.left + targetElement.outerWidth() / 2 - div.outerWidth() / 2) + 'px'
div.css({top: top, left: left, visibility: 'visible'})
.animate({
opacity: 'hide',
top: "-=40"
}, {
duration: 1800,
easing: 'linear',
done: function(){ div.remove() }
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment