Ich versuche, einen Panorama-Regler als jQuery-Plugin, um Kiste, und ich habe den folgenden Code ..jQuery Plugin: Holen Sie sich das „dieses“ Objekt in anderen Funktionen
$.fn.panorama = function(settings) {
var myPanorama = this;
..
this.mousedown(function(e){
//do stuff
$(this).css... //this all work
}
//Call mouseup on document in case user lets go of mouse outside draggable object
$(document).mouseup(function(){
$(myPanorama).easeDragging(); //works but probably not the way to do it
this.easeDragging(); //ideal but refers to wrong object
});
}
Meine Frage ist, wie kann ich verweisen an das Objekt "this" innerhalb des Aufrufs $ (document) .mouseup?
Da es "dieses" denkt, ist das Dokument selbst und nicht das Objekt, das dem Plugin beigefügt ist.
Für jetzt mache ich nur eine Variable und es funktioniert, aber es muss einen besseren Weg geben!
danke!
Sie können auch '$ .proxy()' hier, z. '$ .proxy (function() {this.easeDragging();}, this)' :) –
@Nick: Eine sehr nützliche jQuery-Funktion, die ich nicht kannte, danke :-) –
Ausgezeichnete Antwort, lerne ich etwas jeden Tag neu! – Totomobile