有趣的.toggleClass()

时间:2013-06-18 22:05:39

标签: jquery toggleclass

我正在使用一些非常简单的.toggleClass(),动画为1秒。除动画外,一切正常。我觉得这很有趣。

看看我的fiddle

$(function(){

 $('#main_button').click(function(){
 $('#one, #two, #three, #four').toggleClass("width", 1000);
 return false;
});
});

3 个答案:

答案 0 :(得分:4)

JQuery UI扩展了toggleClass以允许动画,但默认的JQuery .toogleClass()不会动画。你需要在你的小提琴中加入JQuery UI。

答案 1 :(得分:2)

$(function(){

 $('#main_button').click(function(){
 $('#one, #two, #three, #four').animate({'width' :'toggle'}, 1000);
 return false;
});
});

答案 2 :(得分:0)

$(function(){

         $('#main_button').click(function(){
         $('#one, #two, #three, #four').slideToggle({'width' :'toggle'}, 
        1000);
          return false;
          });
        });