-
Notifications
You must be signed in to change notification settings - Fork 148
Open
Labels
Description
Hi,
So i saw issue A method to support IE11 without having to rely on MutationObserver #2 and came up with idea of how to catch resize event, so what are your thoughts.
(function($) {
var stylesCreated = false;
var createStyles = function() {
var style = $('style');
style.text('.jq-custom-frame-resize{position:absolute;top:0;left:0;width:100%;height:100%;border:0;z-index:-1;background:transparent;}');
$('head').append(style);
};
$.fn.elementResize = function(fn) {
if (stylesCreated === false) {
createStyles();
}
var onFrameResize = function() { window.onresize = document.resizeCallback; };
var frame = document.createElement('iframe');
frame.setAttribute('src', 'javascript:;');
frame.className = 'jq-custom-frame-resize';
this.append(frame);
var script = frame.contentWindow.document.createElement('script');
script.textContent = ['(', onFrameResize.toString(), ')();'].join('');
frame.contentWindow.document.resizeCallback = fn;
var style = document.createElement('style');
style.type = 'text/css';
style.textContent = 'body,head{height:100%} body{margin:0;padding:0;}';
var head = frame.contentWindow.document.querySelector('head');
head.appendChild(script);
head.appendChild(style);
};
})(jQuery);it looks simpler it works so... why is your way better?