treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Trigger multiple events on click with Javascript/Jquery

  • Here is the site I'm working on. When I click the black button my gear spins like I want it but what if I want that same click to do something else? (random example: spin the gear AND change the position of something or make an image appear) I'm open to suggestions. Thank as always, hopefully one day I know enough to help others. :)

    P.S. My end goal is to have the gear spin when I click the button and also to have an image in the middle that is replaced by the next image in a list while the gear is spinning..if that makes sense.
  • Try ,#logo

    $(document).ready(function(){
    $("#spinbutton").rotate({bind:{
    click: function(){
    var ang = 0;
    $("#galgear, #logo").rotate({
    duration:6000,
    angle: ang,
    animateTo:ang + 45,
    easing: $.easing.easeOutElastic,
    })
    }
    }
    });
    });
  • I actually updated the post, sorry if I did so after you posted. I really want to add a whole other function to the "click" event so I can make something else happen on the site when I click the button. Check the PS of my post.
  • Just keep to put another effect/function inside click: function() {}

    $(document).ready(function() {
    $("#spinbutton").rotate({bind: {
    click: function() {
    var ang = 0;
    $("#galgear").rotate({
    duration:6000,
    angle: ang,
    animateTo:ang + 45,
    easing: $.easing.easeOutElastic,
    })
    }

    $('body').css('background-image', 'gear-2.jpg'); // Change the image. Like this???? -..-
    // Other functions...
    $('#something1').slideToggle();
    $('#something2').fadeToggle();
    }

    });
    });
  • Thanks I'll try some of this out.