Grow your CSS skills. Land your dream job.

How to create a function?

  • # January 22, 2009 at 8:36 am

    I’d like to make my jQuery a bit more smart by creating functions instead of repeating myself over and over. Take this code as an example:

    Code:
    $(‘#button’).click(function(){
    $(‘#box1′).animate({width: 300, height: 250}, 1000);
    $(‘#box1′).animate({opacity: 0.75}, 2000);
    });

    Now, I’d like to do the very same two animations for another object plus I need the #button (what do you call this element in this example? Trigger?) to be something else. How will I do this best?

    Thanks,
    Oskar

    # January 22, 2009 at 10:40 pm

    Have you seen the screen-casts on jQuery? I think the second one could help you out. Chris shows you how to make you own functions. I highly recommend it for solving your problem, if you haven’t already watched it.

    http://css-tricks.com/video-screencasts … -jquery-2/

    Check it out.

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".