Created
January 4, 2017 10:01
-
-
Save luanvuhlu/86ae0810d719169c9f0ba60e83e52b10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.event.special.widthChanged = { | |
remove : function() { | |
$(this).children('iframe.width-changed').remove(); | |
}, | |
add : function() { | |
var ss = document.createElement('style'); | |
ss.type = "text/css"; | |
ss.innerHTML = "iframe.width-changed {width: 100%;display: block;border: 0;height: 0;margin: 0;}"; | |
document.body.appendChild(ss); | |
var elm = $(this); | |
var iframe = elm.children('iframe.width-changed'); | |
if (!iframe.length) { | |
iframe = $('<iframe/>').addClass('width-changed').prependTo(this); | |
} | |
var oldWidth = elm.width(); | |
function elmResized() { | |
var width = elm.width(); | |
if (oldWidth != width) { | |
elm.trigger('widthChanged', [ width, oldWidth ]); | |
oldWidth = width; | |
} | |
} | |
var timer = 0; | |
var ielm = iframe[0]; | |
(ielm.contentWindow || ielm).onresize = function() { | |
clearTimeout(timer); | |
timer = setTimeout(elmResized, 20); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment