1

Since jQuery 1.9, toggleEvent do not exists anymore, so I am trying to do something like: when someone click at .trigger, the div#map get bigger, when click again, div#map get smaller.

$(".trigger").click(function(){ 
  $("#map").animate({height: '400px'}, 550, function() { $(".trigger").text("see small");
  });
}, function(){
  $("#map").animate({height: '205px'}, 250, function() { $(".trigger").text("see big");
  });
});

If I use "toggle" in 1.8.3 it works fine, but I want to run in 1.9.1 and I don't know how.

Example of the code running in 1.8.3: http://jsfiddle.net/EZ9My/

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Programmeur
  • 1,483
  • 4
  • 22
  • 32

2 Answers2

1
var isSmall = false;
var trigger = $(".trigger").click(function(){
    if (isSmall)
        $("#map").animate({height: '400px'}, 550, function() { trigger.text("see small"); });
    else
        $("#map").animate({height: '205px'}, 250, function() { trigger.text("see big"); });

    isSmall = !isSmall;
});
Joseph Lennox
  • 3,202
  • 1
  • 27
  • 25
0

Try this:

 $(".trigger").click(function(){
     if($("#map").css('height') == '400px'){
       $("#map").stop().animate({height:'205px'},550);
       $(this).text("see big");
     };
     if($("#map").css('height') == '205px'){
        $("#map").stop().animate({height:'400px'},250);
         $(this).text("see small");
     };
 });

jsFiddle: http://jsfiddle.net/EZ9My/1/

Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75