बस इस फंक को आज़माएं (यह न केवल डिव के लिए काम कर सकता है):
function resized(elem, func = function(){}, args = []){
elem = jQuery(elem);
func = func.bind(elem);
var h = -1, w = -1;
setInterval(function(){
if (elem.height() != h || elem.width() != w){
h = elem.height();
w = elem.width();
func.apply(null, args);
}
}, 100);
}
आप इसे इस तरह से उपयोग कर सकते हैं
resized( '.advs-columns-main > div > div', function(a){
console.log(a);
console.log(this);
}, ['I\'m the first arg named "a"!']);
अद्यतन:
आप अधिक प्रगतिशील द्रष्टा का उपयोग कर सकते हैं (यह किसी भी ऑब्जेक्ट के लिए काम कर सकता है, न केवल डोम तत्व)
function changed(elem, propsToBeChanged, func = function(){}, args = [], interval = 100){
func = func.bind(elem);
var currentVal = {call: {}, std: {}};
$.each(propsToBeChanged, (property, needCall)=>{
needCall = needCall ? 'call' : 'std';
currentVal[needCall][property] = new Boolean();
});
setInterval(function(){
$.each(propsToBeChanged, (property, needCall)=>{
try{
var currVal = needCall ? elem[property]() : elem[property];
} catch (e){
var currVal = elem[property];
needCall = false;
propsToBeChanged[property] = false;
}
needCall = needCall ? 'call' : 'std';
if (currVal !== currentVal[needCall][property]){
currentVal[needCall][property] = currVal;
func.apply(null, args);
}
});
}, interval);
}
कर के देखो:
var b = '2',
a = {foo: 'bar', ext: ()=>{return b}};
changed(a, {
foo: false,
ext: true
}, ()=>{console.log('changed')})
जब आप b, a.foo या a.ext को सीधे बदलते हैं, तो यह हर बार 'परिवर्तित' हो जाएगा