I have a function that basically creates an overlay div element that covers the entire page. It also binds a resize event to window so whenever the window is resized the overlay also changes its size:
function stdOverlay() {
var overlay = $('<div />').css({width : $(window).width(), height : $(window).height()});
var overlayResize =
function() {
$(overlay).css({width : $(window).width(), height : $(window).height()});
};
$('body').append(overlay);
$(window).resize(overlayResize);
//... other codes, like remove overlay and unbind the events
//$('div.stdgui-overlay').unbind('resize', overlayResize);
}
each time the function is called it add's an overlay, if there isn't any, and binds a resize event to the window. It also unbinds the event, when it should remove the overlay event. How can I check, if the overlayResize method is bound to window element, to prevent duplicate bindings? something like:
if(overlyResize is not bound to window)
$(window).resize(overlayResize);
else
//do something else or do nothing;