How to use .animate() with a notification system
Hello,
I'm quite a beginner with the JQuery framework. I'm building a very simple notification system showing at the top of the screen.
Here is my actual script :
- function msg(txt) {
- if(txt) {
- $("#message").html(txt);
- $('#message').animate({
- top: '14'
- }, 1000, "easeOutBounce", function() {
- // Animation complete
- setTimeout(
- function() {
- $('#message').animate({
- top: '-66'
- }, 1000 )}, 1500);
- });
- }
- }
Explanation : a message appears from the top center of the screen with a bounce effect. After 1.5s the message disappears.
My problem is that if a second call is made within these 1.5s to the function message(), it's a bit buggy as my message disappears.
I think the best way would be by cancelling the previous "hide" effect. I saw the clearQueue() function but I didn't really understood if that would help me.
Many thanks in advance for your advices!