Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 18:22:17
Original
1224 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template