scottjehl / Respond

A fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more)
MIT License
11.33k stars 3.36k forks source link

IE8 Triggers resize events on DOM changes #264

Open mynameisstephen opened 10 years ago

mynameisstephen commented 10 years ago

As the title suggests, IE8 triggers resize events ( http://stackoverflow.com/questions/1852751/window-resize-event-firing-in-internet-explorer ) whenever the DOM changes. Since the applyMedia function alters the DOM, it is also triggering a resize event. This is somewhat alleviate by the function throttling but on slower computers it keeps the cpu usage quite high and sometimes causes crashes.

One work around would be to only call the applyMedia function when ever the the window height/width. See below.

respond.currentHeight = 0;
respond.currentWidth = 0;

function callMedia(){
    var currentHeight = 0;
    var currentWidth = 0;

    currentHeight = window.innerHeight || document.documentElement.clientHeight;
    currentWidth = window.innerWidth || document.documentElement.clientWidth;

    if (respond.currentHeight != currentHeight || respond.currentWidth != currentWidth) {
        respond.currentWidth = currentWidth;
        respond.currentHeight = currentHeight;

        applyMedia( true );
    }
}
enzy commented 9 years ago

Also experiencing high CPU usage (IE8, WinXP)