Treehouse: Grow your CSS skills. Land your dream job.

Which is better practice…

  • # April 20, 2013 at 6:20 am


    I’m curious if there is a preferred method for writing the following jQuery animation syntax.

    **Method One**

    $(‘.box’).animate({ left: -20 }, 400, ‘linear’);

    **Method Two** (pixels defined)

    $(‘.box’).animate({ left: “-20px” }, 400, ‘linear’);

    Also…is there a difference in single and double quotes? For example, **”-20px”** and **’-20px’**

    Thanks for any suggestions

    # April 20, 2013 at 7:04 am

    There is no difference between using `”` and `’`, people say there is but I have never seen anything to suggest either one is slower or faster than the other.

    As for the animation syntax you can generally just leave off the `px` and use integers as jQuery defaults everything to a pixel value anyway.

    # April 20, 2013 at 9:24 am


    # April 20, 2013 at 11:58 am

    I’d say that `”` vs `’` comes down to which one you’d use most in other contexts, and to keep consistency, IE overall pick one and stick to it =)

    # April 20, 2013 at 2:38 pm

    I prefer using direct numbers over defining the value as px.

    # May 2, 2013 at 4:58 pm

    Cool…thanks for the input

    # May 2, 2013 at 6:10 pm

    For your own sake, I say stick with consistency. My experience has been what made sense to me when I was coding something up today may look like jibberish three weeks from now when I’m working on something else. Then I play with it… then everything falls apart.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.