tags:

views:

72

answers:

3
+1  A: 

You maybe can solve that problem without an if statement. Just adapting your selector might help.

$('.elements:first-child')

for instance. Another could be

$('table').find('tr').find('.elements:nth-child(2)')

jQuery selectors

jAndy
I was just about to suggest this.
DLH
I don't quite understand, If I have a grid... I'll update my question actually...)
Neurofluxation
+3  A: 

Animations are queued by default, so there's no point in applying the second animation within the first animation's callback.

By using filter() you can filter out all of the elements that are not on the same row and then only apply the y animation to them, then you can apply the x animation to the entire collection.

$('.elements')
    .filter(function(){
        return $(this).offset().top !== y;
    })
    .animate({
        top: y
    }, howFast, easeItIn)
    .end().animate({
        left: x
    }, howFast, easeItIn);
J-P
Perfect! Gracias!
Neurofluxation
A: 

The key here is that you can animate multiple properties at the same time. So, remove your callback function, and simply add another property to the params of the first animation:

if ($(window).width()<1259) 
{ 
    if (screenFlipMode == "chained") 
    {
        function(x, y)
        { //Small Chained
            $('.elements').animate({
                top: y,
                left: x
            }, howFast, easeItIn)
        }(x,y); 
    }
}

If either property is already at that value, it won't need to change, and thus that property won't animate. The other one will still animate, though.

Also, jQuery automatically treats numeric values as pixes when using animate(), so there's no need to append "px". That may actually be hurting your performance.

Ryan Kinal