patternjavascriptMinor
jQuery function that modifies a DIV
Viewed 0 times
divfunctionjquerymodifiesthat
Problem
How can I shorten and optimize this code which displays then hides a
My first thought was to combine the functions. However, I would like them to remain separate because at a later date I will additionally incorporate a button which will trigger
DIV?setTimeout(function () {
$('.updateNotification').show().addClass('heightener');
callback();
},2000)
function callback() {
setTimeout(function() {
$( '.updateNotification' ).fadeOut();
}, 10000 );
};My first thought was to combine the functions. However, I would like them to remain separate because at a later date I will additionally incorporate a button which will trigger
callback() in addition to the timer.Solution
I'm not sure how you would shorten this code. However I think that
And in the fashion of fading you could replace
callback is a terrible name for a function that fades a CSS class. Remember that a function signature should represent what a function does and with that said I would rename it to something like fadeUpdateNotification().And in the fashion of fading you could replace
.show() with .fadeIn() to have the div fade in and out - I dunno how your styling/website looks like but that might look nice...Context
StackExchange Code Review Q#36642, answer score: 6
Revisions (0)
No revisions yet.