Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to create a function?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24021
    Oskar
    Participant

    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

    #53442
    eshhy
    Member

    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.

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

    Check it out.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.