简体   繁体   English

如何根据文档宽度更改 div 的内容?

[英]How to Change Contents of a Div Depending on Document Width?

I have simplified my code:我已经简化了我的代码:

Basically, I'm just wondering how to change the arrangement of these divs:基本上,我只是想知道如何改变这些 div 的排列:

<div id='ele1'></div>

<div id='ele_container'>
   <div id='ele2'></div>
   <div id='ele3'></div>
</div>

To this:对此:

<div id='ele1'>
   <div id='ele2'></div>
   <div id='ele3'></div>
</div>

<div id='ele_container'></div>

Depending on screen resolution.取决于屏幕分辨率。 So if the screen resolution is less than 800px- the first, and greater than- the second arrangement.因此,如果屏幕分辨率小于 800 像素 - 第一种排列方式,而大于 - 第二种排列方式。

I know I can use document.width() and an if/else statement using jquery's.html, but this will not account for if the user resizes the window.我知道我可以使用 jquery's.html 使用 document.width() 和 if/else 语句,但是如果用户调整 window 的大小,这将不考虑。

Regards, Taylor问候,泰勒

What you said is correct, use the width and an if/else.你说的是正确的,使用宽度和 if/else。 To handle resizing just use the resize event:要处理大小调整,只需使用 resize 事件:

http://api.jquery.com/resize/ http://api.jquery.com/resize/

You can always detect resize, like this你总是可以检测到调整大小,像这样

window.onresize = function(){ /* stuff */ };

What are you trying to achieve (visually) are you sure it is not possible with plain css?你想达到什么(视觉上)你确定用普通的 css 是不可能的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM