Per quanto ne so, l'unico modo per fare questo sarebbe con un timer.
ho creato un piccolo plugin per jQuery (sì, proprio qui, in questo momento) che fa questo nei confronti di un set di jQuery:
EDIT questo plugin è ora su GitHub: https://github.com/jacobrelkin/jquery-watcher
$.fn.watch = function(property, callback) {
return $(this).each(function() {
var self = this;
var old_property_val = this[property];
var timer;
function watch() {
if($(self).data(property + '-watch-abort') == true) {
timer = clearInterval(timer);
$(self).data(property + '-watch-abort', null);
return;
}
if(self[property] != old_property_val) {
old_property_val = self[property];
callback.call(self);
}
}
timer = setInterval(watch, 700);
});
};
$.fn.unwatch = function(property) {
return $(this).each(function() {
$(this).data(property + '-watch-abort', true);
});
};
Usage :
$('.watch-me').watch('style', function() {
//"this" in this scope will reference the object on which the property changed
if($(this).css('display') == 'block') {
//do something...
}
});
Per cancellare questa proprietà watcher:
$('.watch-me').unwatch('style');
fonte
2010-12-31 04:09:26
L'ho provato localmente e funziona. :) –
Per tutti gli interessati: https://github.com/jrelkin/jquery-watcher –
e quindi quale sarà il codice qui? '//" questo "in questo ambito farà riferimento all'oggetto su cui è stata modificata la proprietà' – GusDeCooL