2012-11-06 69 views
1

我有一个简单的jquery设置为打开滑动面板,然后启动第二个函数以在该面板中启动幻灯片放映。当我关闭面板并再次打开它时,它也会再次调用该功能,因此会给我重复的滑块。第二次打开滑块时停止调用函数

 $(function() { 
    $('a.everyday').click(function() { 
    $('#everyday').addClass('open').stop().animate({top:'30px'},{queue:false,duration:400}); 

    // Activates Blinds jquery image slider 
    $(function() { 

    $('.slideshow').blinds(); 

    }); 
    }); 
}); 

所以。点击功能发生第二次,我想jQuery来没有主动.blinds功能。

回答

0

糟糕。误读需求,这是一个更好的版本。

$(function(){ 
    var opened = 0; 
    $('a.everyday').on('click', function() { 
     $('#everyday').addClass('open').stop().animate({top:'30px'},{queue:false,duration:400}); 
     if(opened < 1){ 
      $('.slideshow').blinds(); 
      opened++; 
     } 

    }); 
}); 
0

加载窗帘应该在你的document.ready,而不是在每一个onclick处理

$(document).ready(function(){ 
    $('.slideshow').blinds(); 
}); 
0
$(function() { 
    var show = new MyShow(); 
    show.initialize(); 
}); 


var MyShow = function(){ 
    this.started = false; 
    var that = this; 
    this.initialize = function(){ 
    $('a.everyday').click(function() { 
      $('#everyday').addClass('open').stop().animate({top:'30px'},{queue:false,duration:400}); 
     if(!that.started){ 
      that.started = true; 
      // Activates Blinds jquery image slider 
      $(function() { 

      $('.slideshow').blinds(); 

     }); 
     }else{return;} 
    }); 
} 
}