Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing $(this) in setTimeout

How do I pass $(this) as a parameter in the setTimeout function (method?)? Here's what I'm doing so far, which is working:

var Variables = {};
Variables.ResizeTimer = false;
Variables.$obj = null;

$('.draggable').resize(function() {
    if (Variables.ResizeTimer !== false) { 
        clearTimeout(Variables.ResizeTimer);
    }
    Variables.$obj = $(this);
    Variables.ResizeTimer = setTimeout(mySizer,
        1000
    );
});
like image 872
Phillip Senn Avatar asked Jul 18 '26 15:07

Phillip Senn


1 Answers

Since Variables looks global you can use it inside the mySizer routine. If you don't want to have global variables you can create a closure:

$('.draggable').resize(function() {
    if (Variables.ResizeTimer !== false) { 
        clearTimeout(Variables.ResizeTimer);
    }
    var $this = $(this);
    Variables.ResizeTimer = setTimeout(function() {
        mySizer($this);
    }, 1000);
});
like image 76
Atanas Korchev Avatar answered Jul 21 '26 03:07

Atanas Korchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!