Home >Web Front-end >JS Tutorial >IE dynamically adds DOM nodes to trigger the window.resize event_javascript skills

IE dynamically adds DOM nodes to trigger the window.resize event_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:22:171230browse

Then there are several events on the page that dynamically add DOM elements. For example, clicking on a certain layer will list the details of the layer at the bottom. In this way, there is no problem under FF and chrome, but under IE6-8, the layout will be re-layout every time.

For example, if I drag a layer, the content of the layer is displayed at the bottom during the dragging process. When I release the layer, the layer will jump back to the position before dragging...

At first I didn’t see that it was a re-layout... Then I demonstrated it for a long time and struggled for a long time. Finally, I felt that the page might be re-layout due to the dynamic addition of DOM nodes that triggers window.resize. ...

Finally, I couldn't help but shout "Thank godness...." in my heart. Fortunately, changing the height of the window has no effect on the page layout, otherwise it would be really troublesome...

Copy code The code is as follows:

bindResizeWindow:function(){
var obj = this;
$(window).resize(function(){
var newWidth = $(window).width();
if(newWidth == obj.windowWidth){return;}
obj.initUI();
obj.createUI();
obj.windowWidth = newWidth;
});
},


As long as The binding method only needs to trigger the relayout event when the width changes...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn