How to simplify code and how animate an element inside a another element
Hi guys, I'm new here and I'm learning jQuery.
I have this piece of code:
- $('#portfolio ul li').mouseenter(function(){
-
- $('.overlay', this).stop().animate({
- opacity: '0.5'
- }, 250, 'easeInOutQuint');
-
- $('.overview', this).stop().animate({
- top: '50%',
- left: '50%',
- margin: '-50 0 0 -125'
- }, 250, 'easeInOutQuint');
-
- $('.link', this).stop().animate({
- bottom: '50%',
- right: '50%',
- margin: '-50 -125 0 0'
- }, 250, 'easeInOutQuint');
-
- $('.overview', this).add('.link', this).mouseenter(function(){
- $(this).stop().animate({
- color: '#e74b3c'
- }, 300, 'easeInOutQuint');
- });
-
- }).mouseleave(function(){
-
- $('.overlay', this).stop().animate({
- opacity: '0'
- }, 250, 'easeInOutQuint');
-
- $('.overview', this).stop().animate({
- top: '50%',
- left: '-100',
- margin: '-50 0 0 0'
- }, 250, 'easeInOutQuint');
-
- $('.link', this).stop().animate({
- top: '50%',
- right: '-100',
- margin: '-50 0 0 0'
- }, 250, 'easeInOutQuint');
-
- $('.overview', this).add('.link', this).mouseleave(function(){
- $(this).stop().animate({
- color: '#FFFFFF'
- }, 300, 'easeInOutQuint');
- });
-
- });
The first question is how can I simplify the code, to stay DRY.
The second question is how can I animate an icon that is just animated. When the mouse enter in the parent element ( <li> ), these icons (
$('.overview') and
$('.link') ) slide respectively from right and left to the center. What I want is that when the
mouseenter on an icon, this become red with an animation.
Actually, if I enter on the <li> element and on the icon (while it is moving), the icon become red and remains red. I think that this code need an optimization...
Thank for your availability.