window.addEvent( 'domready', function(){
var m = new Fx.Morph( $('a'), {duration: 'long', fps: 50 });
var size = $H( $('a').getStyles('width','height', 'margin-left', 'margin-top'));
$('a').addEvents({
'mouseenter': function(){
m.cancel();
m.start({
'width': [ size.width, 400 ],
'height': [ size.height, 400 ],
'margin-left': [ size.get('margin-left'), '-200' ],
'margin-top': [ size.get('margin-top'), '-200' ]
});
},
'mouseleave': function(){
m.cancel();
m.start({
'width': [ 400, size.width ],
'height': [ 400, size.height ],
'margin-left': [ '-200', size.get('margin-left') ],
'margin-top': [ '-200', size.get('margin-top') ]
});
}
});
});
.divs {
width:200px;
height:200px;
position:absolute;
left:50%;
top:50%;
background-color: silver;
margin-top: -100px;
margin-left: -100px;
}
<div id="a" class="divs"></div>
Zwróć uwagę na to że kiedy zjedziesz z elementu przed końcem animacji to będzie przeskok wielkości i zmniejszenie, nie jest błąd jest to spowodowane tym że na sztywno są ustawione wartości dla width i height. Dla płynnego rozszerzania i zmniejszania potrzebne jest policzenie przyrostu wartości width i height tak by było wiadomo do ilu przyrosło przed zjechaniem / wjechaniem myszki z / na element.
EDIT:
Żeby nie było przeskoku, należy nie podawać wartości początkowej animacji.
window.addEvent( 'domready', function(){
var m = new Fx.Morph( $('a'), {duration: 'long', fps: 50 });
var size = $H( $('a').getStyles('width','height', 'margin-left', 'margin-top'));
$('a').addEvents({
'mouseenter': function(){
m.cancel();
m.start({
'width': 400,
'height': 400,
'margin-left': '-200' ,
'margin-top': '-200'
});
},
'mouseleave': function(){
m.cancel();
m.start({
'width': size.width,
'height': size.height ,
'margin-left': size.get('margin-left'),
'margin-top': size.get('margin-top')
});
}
});
});
http://skowronline.pl/a/