Simplest Classname Switcher

On 5-29-2007, in Coding, JavaScript, by Alex

Simplest JS function to add/remove custom classname with carrying about another classes.
just to remember.

function toggleClassName(obj,sClassName,switcher){
	if(switcher){
		if(obj.className.indexOf(sClassName)==-1)
			obj.className=obj.className + ' ' + sClassName;
	}else{
		var re = new RegExp(sClassName,'g');
		obj.className=obj.className.replace(re,'');
	}
}


australian online casino guidesapienti sat

 

links:
MipTV Media Market
Content 360 Pitching Competition @ MipTV

our project/concept:
Cont-Act! Content Actual. Link Different! is in BBC’s category “On-demand Participation”

Support us! 🙂

P.S. We won!

 

There is no brand new subject, really.
even 2 old articles (Vertical centering using CSS and CSS Vertical Centering again) from this blog.

2 problems:
1) Small height: if browser height is smaller than main container (for all browsers):


function adjustHeight(){
   if(document.body.offsetHeight > 450){
      document.body.style.height='100'+'%';
   }else{
      document.body.style.height='450px';
   }
}

onload and onresize, of course.

2) IE7: this rule:

#ContainerDiv {position: relative; top: -50%;}

moves the #ContainerDiv above the top browser’s border for 50%. Reasonable, huh.

The cure:

#ContainerDiv {position: relative; top: expression(document.body.offsetHeight/2-this.offsetHeight/2);}

for custom IE7 CSS file using cond. comments:

<!--[if IE 7]>
<link rel="stylesheet" href="/css/ie7.css" type="text/css" media="screen" />
<![endif]-->

 

TextSize (font-size): EM vs %

On 9-13-2006, in Coding, CSS, HTML, by Alex

Don’t use em for font-size. Use %.
Usually 1em=100%.

Create a model:


<p style="font-size: 1em;">1 em Lorem Ipsum text</p>
<p style="font-size: 100%;">100% Lorem Ipsum text</p>

Then try to change text size (IE: View -> Text Size or Ctrl+Scroll) and you’ll get the difference.
But better just save the time and don’t use ems 😉

Disclamer: of course px is EVIL 🙂 We don’t talk about fixed font-sizes at all.
Disclamer #2. Of course Opera and FireFox are best browsers and they change not only font-size but everything. I am talking about damn IE.

 

Addition to my wish list

On 9-11-2006, in Just another blog, by Alex

CS FM 07. Wireless transmitter and Card Reader with LCD Display

This innovative car MP3 player with FM transmitter and LCD display supports SD/MMC card, MP3, USB flash disk, Hard disk, CD/DVD. Now you can take your music from any memory card and listen to it in the car radio or home audio.

Wish List Page is new page at my blog 😉