【问题标题】:Jquery Toggle events not called未调用 Jquery Toggle 事件
【发布时间】:2014-03-06 12:24:01
【问题描述】:

我正在尝试使用 jquery 切换 div 以显示隐藏子项。我正在尝试在切换打开事件和关闭事件时将类添加到父项。我们如何跟踪切换事件? Here is fiddle

$("#flip").click(function(){
     $("#panel").toggle();
 });

$("#panel").toggle(
  function() {
    alert("first event");
  }, function() {
    alert("second event");
  });

【问题讨论】:

  • 没有切换事件 - slideToggle() 切换显示全部 - 它不会触发任何事件
  • 对不起,是slideToggle,和toggle差不多。
  • SlideToggle 采用一个功能,而不是两个。
  • 你能用 Toggle 做吗?对不起代码

标签: jquery css toggle


【解决方案1】:

您可以在调用slideToggle() 时指定一个complete 回调,您可以在其中确定您的元素是向上滑动还是向下滑动。

$("#flip").click(function(){
    $("#panel").slideToggle(function() {
        if($(this).is(':visible')) {
            alert('Panel is visible');
            // code to add class. "this" refers to the panel here
        }
        else {
            alert('Panel is not visible');
            // code to remove class. "this" refers to the panel here
        }
    });
});

更新fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多