In questo tutorial imparerete come far visualizzare notifiche flash ai vostri utenti creando un plugin jQuery.
Questo script potrebbe ritornarvi utile se desiderate notificare l’avvenuto inserimento di un record, di un prodotto aggiunto al carrello, o per qualsiasi altro evento.
(function($) {
$.fn.flash_message = function(options) {
options = $.extend({
text: ‘fatto’,
time: 1000,
how: ‘before’,
class_name: ”
}, options);
return $(this).each(function() {
if( $(this).parent().find(‘.flash_message’).get(0) )
return;
var message = $(‘‘, {
‘class’: ‘flash_message ‘ + options.class_name,
text: options.text
}).hide().fadeIn(‘fast’);
$(this)[options.how](message);
message.delay(options.time).fadeOut(‘normal’, function() {
$(this).remove();
});
});
};
})(jQuery);
ESEMPIO
$(‘#contenitore-notifiche’).flash_message({
text: ‘Prodotto aggiunto al carrello!’, // testo da mostrare
how: ‘append’, // ['append', 'prepend', 'before', 'after']
time: 1000, // per quanto tempo il messaggio deve essere visibile?
class_name: ‘success’ // classi css addizionali
});
fonte: www.sastgroup.com






