Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-20-2012, 05:25 AM   PM User | #1
HDRebel88
Regular Coder

 
Join Date: May 2011
Posts: 112
Thanks: 11
Thanked 5 Times in 5 Posts
HDRebel88 is an unknown quantity at this point
Adding border when window is resized?

My page is auto centered when some with a monitor bigger than what I developed for views the page. I want to add a left border to my left div tag when the screen is over a certain size.

Here's what I have:

the div tag is this:

Code:
<div class="left"></div>
css
Code:
.left{
width: 240px;
min-height: 548px;
background: #97D38B;
float: left;
border: 0px;
border-bottom: 2px;
border-style: solid;
border-collapse: collapse;
border-color: #0F5400;
}

javascript:

Code:
window.onresize=resized;
window.onload=resized;
function resized(){
if (window.innerWidth)
        {
        screenWidth=window.innerWidth;
        }
  else if (document.documentElement && document.documentElement.clientWidth)
        {
         screenWidth=document.documentElement.clientWidth;
        }        
  else if(document.body)
        {
        screenWidth=document.body.clientWidth;
        }
		
if (screenWidth<=1015)
document.getElementById('header_float').style.position = 'absolute';
else
document.getElementById('header_float').style.position = 'fixed';

if (screenWidth>1015)
document.getElementById('left').style.borderLeft = '2px';
}
The last bit of code document.getElementById('left').style.borderLeft = '2px'; doesn't seem to work.
HDRebel88 is offline   Reply With Quote
Old 05-20-2012, 06:34 AM   PM User | #2
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
Hi

Quote:
Here's what I have:
the div tag is this:

<div class="left"></div>
Code:
if (screenWidth>1015)
document.getElementById('left').style.borderLeft = '2px';
}



In your code the div has no Id 'left'.


Just an idea

You could create a new class and change to that --- still need to give the div and id though.

Code:
var styleLrg = document.getElementById('left');
styleLrg.className = "newClassName";
LT
__________________
Ask not what can I do for myself, but what can I do for others

"The greatest revenge is to accomplish what others say you cannot do."
~ Unknown

Last edited by low tech; 05-20-2012 at 06:39 AM..
low tech is offline   Reply With Quote
Users who have thanked low tech for this post:
HDRebel88 (05-20-2012)
Old 05-20-2012, 06:39 AM   PM User | #3
HDRebel88
Regular Coder

 
Join Date: May 2011
Posts: 112
Thanks: 11
Thanked 5 Times in 5 Posts
HDRebel88 is an unknown quantity at this point
Quote:
Originally Posted by low tech View Post
Hi

In your code the div has no Id 'left'.


Just an idea

You could create a new class and change to that --- still need to give the div and id though.

Code:
var styleLrg = document.getElementById('left');
styleLrg.className = "newClassName";
LT
Thanks. I never use ID tags in html so that always throws me off.

Anyway, I just did it with CSS, by adding the border, and positioning it off the screen to the left by the equivalent pixels of the border width.

i.e; border-left:2px; position: relative; left: -2px;

So then it becomes visible on the window resize.

Last edited by HDRebel88; 05-20-2012 at 06:41 AM..
HDRebel88 is offline   Reply With Quote
Old 05-20-2012, 06:46 AM   PM User | #4
low tech
Regular Coder

 
low tech's Avatar
 
Join Date: Dec 2009
Posts: 740
Thanks: 149
Thanked 67 Times in 67 Posts
low tech is on a distinguished road
Hi HDRebel88

Cool -- whatever works eh

LT
__________________
Ask not what can I do for myself, but what can I do for others

"The greatest revenge is to accomplish what others say you cannot do."
~ Unknown
low tech is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:56 PM.


Advertisement
Log in to turn off these ads.