How to attach window resize event
Hello there.
Im using the plugin template found in the plugin authoring tutorial in the plugin page.
I need to reposition the element plugin is attached after window resize event.
Like this:
(function($){
var methods = {
init : function( options ) {
return this.each(function(){
// Do something with the element(s) plugin is attached.
// Call the reposition method
$(window).bind('resize.tooltip', methods.reposition);
});
},
reposition : function() {
// Reposition the element(s) in the window resize event.
}
};
$.fn.tooltip = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.tooltip' );
}
};
})( jQuery );
Am I in right footsteps?
How do I get the element plugin is attached in the reposition method?
Why I cannot use this.each in the reposition method? It says this is not defined?
Clearly i have missed something. The scope is really confusing to me.
Please help me to understand plugins better.
Thanks.