I have been making a jQuery morphing button type thing.
$(document).ready(function() {
var morphObject = {
button: $('button.morphButton'),
container: $('div.morphContainer'),
overlay: $('div.overlay'),
content: $('h1, p'),
init: function() {
this.buttonPress();
},
buttonPress: function() {
var mO = morphObject;
this.button.on('click', function() {
mO.button.fadeOut(200);
setTimeout(mO.containerMove, 200);
});
},
containerMove: function() {
var mO = morphObject;
span = $('span.close');
mO.overlay.fadeIn();
mO.container.animate({
top: 300,
left: '50%',
width: 600,
height: 400,
marginLeft: -300 },
400, function() {
mO.content.fadeIn();
span.fadeIn();
mO.close();
});
},
close: function() {
var mO = morphObject;
if ( mO.container.find('span.close').length ) return;
$('<span class="close">X</span>').appendTo(mO.container);
var span = $('span.close');
mO.overlay.add(span).on('click', function() {
mO.content.fadeOut();
span.fadeOut();
mO.overlay.fadeOut();
setTimeout(mO.animateBack, 200);
});
},
animateBack: function() {
var mO = morphObject;
mO.container.animate({
top: 150,
left: '20%',
width: 200,
height: 70,
marginLeft: -100 },
400, function() {
mO.button.fadeIn(300);
});
}
}
morphObject.init();
});
Basically, I would love to have any feedback on what I can improve. Please tell me if I have used any bad coding practises or methods which will cause slow performance.