1

从 jQuery 1.9 开始,toggleEvent不再存在,所以我试图做类似的事情:当有人点击时.triggerdiv#map变大,当再次点击时,div#map变小。

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

如果我在 1.8.3 中使用“切换”它工作正常,但我想在 1.9.1 中运行但我不知道如何。

在 1.8.3 中运行的代码示例:http: //jsfiddle.net/EZ9My/

4

2 回答 2

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;
});
于 2013-03-29T17:24:53.640 回答
0

试试这个:

 $(".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/

于 2013-03-29T17:28:32.150 回答