Cereal Killer
Cereal Killer

Reputation: 3414

Add a resize event handler only once

I have a widget that insert a div element in the DOM; that div needs some js that handles the resize event;

the problem is:

do you have any suggestion about how to implement this?

Upvotes: 0

Views: 474

Answers (1)

KQI
KQI

Reputation: 320

Honestly, I didn't get most of workflow explained as you didn't provide any html and js but I hope the following works for you:

var resized = 0;                     // works as a flag
$( window ).on('resize', function () { 
     if ( resized++ >= 1 ) return;
     // do something here.. 
     console.log('resized once');    // console.log as an example! 
});

Good luck.

Upvotes: 1

Related Questions