Created
January 31, 2014 12:14
-
-
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.
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
.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; | |
} |
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
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