जब भी आप ऐसा कुछ करते हैं जो तत्व की ऊंचाई को बदलता है, तो एक ईवेंट ट्रिगर करें।
$("#somelement").slideDown().trigger("heightchange");
अब आप कि करने के लिए बाध्य कर सकते हैं:
$("body").on("heightchange",function(e){
var $el = $(e.target); // the element that has a new height.
});
तुम भी jQuery तरीकों कि ऊंचाई बदल सकते हैं और उन्हें पहले और विधि और ट्रिगर उपयोग करने के बाद ऊंचाई का परीक्षण हो सकता है की एक बहुत कुछ कर सकता है monkeypatch तदनुसार घटना। नीचे एक अपरीक्षित उदाहरण
var topatch = ["slideup","slidedown","height","width","attr","css","animate"];
$.each(topatch,function(i,method){
var oldfn = $.fn[method];
$.fn[method] = function(){
return this.each(function(){
var $this = $(this), currHeight = $this.css("height"),
result = oldfn.apply($this,arguments);
// check for promise object to deal with animations
if ($.isFunction(result.promise)) {
result.promise().done(function(){
if (currHeight != $this.css("height")) {
$this.trigger("heightchange");
}
});
return;
}
if (currHeight != $this.css("height")) {
$this.trigger("heightchange");
}
});
};
});
स्रोत
2012-12-18 15:37:23
यह प्रो पर बहुत तीव्र होगा। क्या ऐसे विशिष्ट तत्व हैं जिन्हें आप निगरानी करना चाहते हैं? यदि हां, तो यह बहुत कठिन नहीं है। आप बस एक टाइमर बनाते हैं और ऊंचाई को अलग होने के लिए देखते हैं। – SpYk3HH
अधिक विशिष्ट बनें, आप किस तत्व पर यह कर रहे हैं? –
संभावित डुप्लिकेट: http://stackoverflow.com/questions/172821/detecting-when-a-divs-height-changes-using-jquery – tungd