0

I want this svg drawing to go up when it's clicked and then go down when it's clicked again, and also go up and down a little when it's hovered. I managed to do the hover part and to make it go up once it's clicked, but I cant make it go down when it's clicked again. I figured using "toggle" instead of "click" would work:

$('#globoamarillo1').click(function() {
$("#globoamarillo1").animate({top: '-=200px'}, 1000);

(changed to)

$('#globoamarillo1').toggle(function() {
$("#globoamarillo1").animate({top: '-=200px'}, 1000);

But when I use that the drawing goes crazy and flies out of the picture instantly.

https://jsfiddle.net/vqvLyctj/3/

So how can I make it go down when it's clicked again?

Robert Longson
  • 118,664
  • 26
  • 252
  • 242

1 Answers1

0

Your fiddle doesn't seem to do anything when I look at it but here is a thought:

<script>
var myToggle = 0;

$('#globoamarillo1').click(function() {
myToggle = (myToggle + 1) % 2;
if( myToggle > 0 ){ $("#globoamarillo1").animate({top: '-=200px'}, 1000); }
   else { $("#globoamarillo1").animate({top: '+=200px'}, 1000); }
}
</script>

Everything time you click on it the variable myToggle will toggle between zero(0) and one(1). Easy peazy. :-)

Mark Manning
  • 1,427
  • 12
  • 14