Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Roy Marchand http://www.expertsrt.com

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Making Columns Render with Equal Height

A problem sometimes faced by web developers is trying to get two (or more) columns in a multi-column layout to be the same height when the content is variable. Rather than using an arbitrary hardcoded value, the heights can be equalized (to the tallest one) with this script.

Assuming two columns in div tags with ids of "leftside" and "rightside" this script will set the height of the shorter to the height of the taller one. The page must be in standards compliant mode with a valid doctype or IE will mess it up in quirks mode. For longer articles and discussion visit my home site... ERT
<script type="text/javascript">
function setH()
{
   var maxH = Math.max(document.getElementById('leftside').offsetHeight,document.getElementById('rightside').offsetHeight);
   document.getElementById('leftside').style.height=maxH+'px';
   document.getElementById('rightside').style.height=maxH+'px';
}
onload=setH;
</script>

Setting Element Height Dynamically

There are times when you need to control the height of an element based on the screen size. However youcan control the user setup, and of course there are browser differences so this snippet handles browser and object detection and sets the height during page load and for any re-sizing event.

An example of the snippet in action

  var minorOffset = (document.all)? 25 : 38;
   function setHgt()
   {
      var sHGT;
      srcobj=document.getElementById('main');
      if (self.innerHeight)
      {
	   sHGT = self.innerHeight;
	}
      else
      { 
         if (document.documentElement && document.documentElement.clientHeight)
         {
	      sHGT = document.documentElement.clientHeight;
         }
         else
         {
            if (document.body)
            {
              sHGT = document.body.clientHeight;
            }
         }
      }
      sHGT=sHGT-(document.getElementById('main').offsetTop+minorOffset);
  document.getElementById('main').style.height=sHGT+"px";
   }
window.onload=setHgt;
window.onresize=setHgt;

Javascript to put a hotkey on a Web Page

// description of your code here
This page will fire an event when the key specified in the
variable key1 is pressed.

Cd&
http://www.expertsrt.com

var key1="32";
var x='';
function handler(e) 
{
  if (document.all) {
  var evnt = window.event; 
  x=evnt.keyCode;
}
else
x=e.charCode;
if (x==key1) location.href='http://www.expertsrt.com';
}
if (!document.all){
window.captureEvents(Event.KEYPRESS);
window.onkeypress=handler;
}
else
{
document.onkeypress = handler;
} 
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS