Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28541

Apply a CSS block onresize?

Path csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail
From Tuxedo <tuxedo@mailinator.com>
Newsgroups comp.lang.javascript
Subject Apply a CSS block onresize?
Date Wed, 19 Aug 2015 16:51:25 +0200
Organization albasani.net
Lines 68
Message-ID <mr255d$eff$1@news.albasani.net> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 8Bit
X-Trace news.albasani.net f9gJD5Ze8ZxnCSjpvleETYBsG+fUpd9bNAi0YqCJddJisrU3wATgcMtlC6UCj6pGVye7JQDUD5hsYvQghu/IXhSMkPffawtwEb6/4lwAa+VJNV/zqCSBDsrSS7foXSLW
NNTP-Posting-Date Wed, 19 Aug 2015 14:51:25 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="4OgBuVJAIzWoQm7eanm4BOlEPS4HUFxAA89RV/dh3WRXZoiz0BSKCuMFVlo+VDdpgN4FH92T74teM0NglId8TbhVEDMobFAnx1z75gFaGpsaAykB+4/xonzF1G13trMQ"; mail-complaints-to="abuse@albasani.net"
Cancel-Lock sha1:5MvtsllFqsnjjIqzLowkhCQtMbo=
Xref csiph.com comp.lang.javascript:28541

Show key headers only | View raw


Hello,

I'm not sure what conventions exist but I would like to apply a set of CSS 
rules to an HTML object when resizing the window. First there are one of 
two display styles that take effect on a div depending on the document's 
scroll width:

#menu_small{
border: solid red 1px;
/* and many more properties */
}

#menu_big{
border: solid green 1px;
/* and many more properties */
}

<body onresize="change_display()">

<script>
if(d.body.scrollWidth < 800){
d.write('<div id="menu_small">');
}
else{
d.write('<div id="menu_big">');
}
</script>

<h2>My big or small menu</h2>
<li><a href="#">Item 1</li>
<li><a href="#">Item 2</li>
etc.

<script>
d.write('</div>');
</script>

This works while the page loads, since the browser should know its scroll 
width before it's finished fully loading.

To make the alternate set of style properties take effect also when 
resizing the window, I can run a function onresize modifying the styles 
that exist in the div by collecting and resetting all individual style 
properties via for example getElementByTagName('a') in a loop as well as 
other more specific ID elements within the block by getElementById('...');

Is there a shorter and better way such as dynamically switching the ID of 
the html object along with the set of styles found in its corresponding and 
just changed CSS block? For example, is it possible to call a function 
onresize to do somethng as follows?:

function change_display(){
if(d.body.scrollWidth < 800){

/* If div ID is not already 'menu_small', switch the HTML div ID to 
'menu_small' and apply all properties found within that CSS block */

}
else{

/* If div ID is not already 'menu_big', switch the HTML div ID to 
'menu_big' and apply all properties found within that CSS block */

}

Many thanks for any tips!

Tuxedo

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Apply a CSS block onresize? Tuxedo <tuxedo@mailinator.com> - 2015-08-19 16:51 +0200
  Re: Apply a CSS block onresize? Martin Honnen <mahotrash@yahoo.de> - 2015-08-19 17:38 +0200
    Re: Apply a CSS block onresize? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-19 18:52 +0200
      Re: Apply a CSS block onresize? Tuxedo <tuxedo@mailinator.com> - 2015-08-19 22:17 +0200

csiph-web