0

I have a resize method in my js file :

$(window).resize(function(){
    my_function();
});

In it i have loads of other functions which need to be called when the window is resized (for the responsive part of a website) ,i have not included all these functions as the problem i keep facing is the same in the one i am about to post.

It can't be simpler :

function my_function() {
    console.log('1');
    $('body').click(function(){
        console.log('2');
    });
   }
   my_function();
//when the function is called the console logs 1,when you click on the body ,it logs 2.

Now the problem, when I resize the window (for example : from full window to half in 2s),the resize() fires a couple of times (for example : 10 [every time it's different]).I know this because in the console the number 1 is called/logged 10 times as the window is being resized.Now,after i finished resizing the window, when i click on the body, the console logs the number 2 the same amount of times (10). Why ? And how can i make it fire the click.function only once ?

Alex.

UPDATE 1 : in addition,every subsequent click on the body logs 2 another 10 times (so if i click 5 times,the console will log the number 2 50 times.

lordZ3d
  • 540
  • 6
  • 20
  • I think this what you need. http://stackoverflow.com/questions/5489946/jquery-how-to-wait-for-the-end-of-resize-event-and-only-then-perform-an-ac – dsharew Dec 15 '14 at 15:52
  • It made a slight difference,but the issue still persists. – lordZ3d Dec 15 '14 at 16:13

0 Answers0