https://jsfiddle.net/57org2ve/2/
HTML:
<div id="at" style="width:100%;background:red">
This is a div, you can click on me or resize me.
</div>
JavaScript:
$('#at').resize(function(){alert(1)})
$('#at').click(function(){alert(2)})
I think you need to refer this link
http://marcj.github.io/css-element-queries/
I have just checked with this js this is worked for me download this file and check it ,hope this will help you
var element = document.getElementById('at');
new ResizeSensor(element, function() {
console.log('Changed to ' + element.clientWidth);
});
Maybe use a little function which check onresize if the width of element has changed. Resize the browser and check out console log result.
$(window).resize(function(){
var obj = $('#at')[0];
if(detectResize(obj)) console.log('resize detected');
});
function detectResize(getObject){
var getWidth = getObject.getBoundingClientRect().width;
if(getObject.currentWidth===getWidth){
return false;
} else {
getObject.currentWidth = getWidth;
return true;
}
}
#at{
width:100%;
max-width:400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="at" style="background:red">
This is a div, you can click on me or resize me.
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With