0

Can someone help me fix this code, please? What I want is to block the live ('click') function until the sliddingright function is done.

('li.menu-item').live('click', function(event){
    if( !$(this).is(':animated')) 
    {
    sliddingright(page_id_target_right,previous_right_old,previous_right,next_right,pages_numbers);
    }
});
davehale23
  • 4,374
  • 2
  • 27
  • 40
Romain
  • 407
  • 2
  • 9
  • 20

2 Answers2

2

Just add a return statement to your slidingright function that returns 'standby' once the function has completed its task, save it and check its value next time 'click' is called.

Like so :

var state = 'standby';
('li.menu-item').live('click', function(event){
    if( !$(this).is(':animated') && state == 'standby' ) 
    {
        state = 'processing';
        state = sliddingright(page_id_target_right,previous_right_old,previous_right,next_right,pages_numbers);
    }
});
Raindal
  • 3,227
  • 15
  • 14
  • Thanks for your answer, I tried your solution but this isn't working in my case... $(document).ready(function() { var state = 'standby'; $('li.menu-item').live('click', function(event){ if( !$(this).is(':animated') && state == 'standby' ) { state = 'processing'; state = sliddingright(page_id_target_right,previous_right_old,previous_right,next_right,pages_numbers); } }); At the end of the sliddingright function I'm returning the "standby" state – Romain Dec 19 '12 at 17:11
  • The problem is that into my sliddingright function, I'm sending the state "standby" even if the animation aren't finish – Romain Dec 20 '12 at 12:06
  • I resolve the problem, I add : state = 'standby'; return state; On my last animated action in my sliddingright function – Romain Dec 20 '12 at 12:34
0

Try:

clickMe = function() {
$('li.menu-item').live('click', function(event) {
    $('li.menu-item').off('click');
    sliddingright(page_id_target_right, previous_right_old, previous_right, next_right, pages_numbers);
});
    $('li.menu-item').on("click", clickMe);
};​
Anujith
  • 9,370
  • 6
  • 33
  • 48