Online Shopping : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

25 of 31 people (81%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I have dynamic borders with layers in NN4?
How to build buttons with NN4?

Apr 2nd, 2009 06:56
engatoo engatoo, Rockys rainwal, Raj Aryan, Martin Honnen, http://jaipurtravelguiderajasthan.blogspot.com/


Some button effects in guis are simply dynamic border changes for 
instance try
<HTML>
<HEAD>
<STYLE>
TD { border: 1px solid lightgrey; }
</STYLE>
<SCRIPT>
function buttonOn (el) {
  el.style.borderLeft = el.style.borderTop = '1px solid white';
  el.style.borderRight = el.style.borderBottom = '1px solid darkgray';
}
function buttonOff (el) {
  el.style.borderLeft = el.style.borderTop = '1px solid lightgrey';
  el.style.borderRight = el.style.borderBottom = '1px solid lightgrey';
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="lightgrey">
<TABLE>
<TR>
<TD ONMOUSEOVER="buttonOn(this)"
    ONMOUSEOUT="buttonOff(this)"
>
a button
</TD>
<TD ONMOUSEOVER="buttonOn(this)"
    ONMOUSEOUT="buttonOff(this)"
>
a 2nd button
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
with IE4/5 or NN6 and you will have some button appearance similar to 
the IE toolbar buttons.
NN4 doesn't allow for dynamic border style changes so much work is 
needed to get a similar effect for NN4. The following code sets up a 
Border object which you can pass a layer to for which a border is set 
up using dynamically created layers. The Border object is generic and 
can be applied to every layer/positioned element in NN4. An example is 
provided. The Border object is then further used to attempt to 
implement some ButtonBorder similar to the effect above and to build 
two example buttons. The buttons are not very handy as the need 
absolute positioning but they work.
<HTML>
<HEAD>
<STYLE>
.borderable { position: relative; }
.button { position: absolute; }
A.buttonLink { text-decoration: none; color: black; }
#buttonBar { 
  position: absolute; 
  width: 385px; height: 28px;
  clip: rect(0 385 28 0);
  left: 100px; top: 200px;
  layer-background-color: lightgrey;
}
#button1 { position: absolute; left: 103px; top: 203px; }
#button2 { position: absolute; left: 300px; top: 203px; }
</STYLE>
<SCRIPT LANGUAGE="JavaScript1.2">
function Border (layer, width, color) {
  this.layer = layer;
  this.setBorderWidth(width);
  this.setBorderColor(color);
  this.initLayers();
  this.updateBorders();
  this.initVisibility();
}
function Border_initLayers () {
  this.borderLayer = new Layer(this.layer.clip.width);
  this.borderTopLayer = new Layer(this.borderWidth, this.borderLayer);
  this.borderRightLayer = new Layer(this.borderWidth, 
this.borderLayer);
  this.borderBottomLayer = new Layer(this.borderWidth, 
this.borderLayer);
  this.borderLeftLayer = new Layer(this.borderWidth, this.borderLayer);
  if (this.layer.zIndex == 0)
    this.layer.zIndex = 1;
  this.borderLayer.zIndex = this.layer.zIndex - 1;
}
Border.prototype.initLayers = Border_initLayers;
function Border_updateBorders () {
  this.positionBorders();
}
Border.prototype.updateBorders = Border_updateBorders;
function Border_positionBorders () {
  this.borderLayerWidth = 
    this.layer.clip.width + this.borderLeftWidth + 
this.borderRightWidth;
  this.borderLayerHeight = 
    this.layer.clip.height + this.borderTopWidth + 
this.borderBottomWidth;
  this.borderLayer.clip.width = this.borderLayerWidth;
  this.borderLayer.clip.height = this.borderLayerHeight;
  this.borderLayer.left = this.layer.pageX - this.borderLeftWidth;
  this.borderLayer.top = this.layer.pageY - this.borderTopWidth;
  this.borderTopLayer.clip.height = this.borderTopWidth;
  this.borderTopLayer.clip.width = this.borderLayerWidth;
  this.borderTopLayer.bgColor = this.borderTopColor;
  this.borderTopLayer.left = 0;
  this.borderTopLayer.top = 0; 
  this.borderRightLayer.clip.height = this.borderLayerHeight;
  this.borderRightLayer.clip.width = this.borderRightWidth;
  this.borderRightLayer.bgColor = this.borderRightColor;
  this.borderRightLayer.left = this.layer.clip.width + 
this.borderLeftWidth;
  this.borderRightLayer.top = 0;
  this.borderBottomLayer.clip.height = this.borderBottomWidth;
  this.borderBottomLayer.clip.width = this.borderLayerWidth;
  this.borderBottomLayer.bgColor = this.borderBottomColor;
  this.borderBottomLayer.left = 0;
  this.borderBottomLayer.top = this.layer.clip.height + 
this.borderTopWidth; 
  this.borderLeftLayer.clip.height = this.borderLayerHeight;
  this.borderLeftLayer.clip.width = this.borderLeftWidth;
  this.borderLeftLayer.bgColor = this.borderLeftColor;
  this.borderLeftLayer.left = 0;
  this.borderLeftLayer.top = 0;
}
Border.prototype.positionBorders = Border_positionBorders;
function Border_setBorderWidth (width) {
  this.borderWidth = width;
  this.borderTopWidth = width;
  this.borderRightWidth = width;
  this.borderBottomWidth = width;
  this.borderLeftWidth = width;
}
Border.prototype.setBorderWidth = Border_setBorderWidth;
function Border_setBorderColor (color) {
  this.borderColor = color;
  this.borderTopColor = color;
  this.borderRightColor = color;
  this.borderBottomColor = color;
  this.borderLeftColor = color;
}
Border.prototype.setBorderColor = Border_setBorderColor;
function Border_initVisibility () {
  this.show();
}
Border.prototype.initVisibility = Border_initVisibility;
function Border_show () {
  this.borderTopLayer.visibility = 'show';
  this.borderRightLayer.visibility = 'show';
  this.borderBottomLayer.visibility = 'show';
  this.borderLeftLayer.visibility = 'show';
  this.borderLayer.visibility = 'show';
}
Border.prototype.show = Border_show;
function Border_hide () {
  this.borderTopLayer.visibility = 'hide';
  this.borderRightLayer.visibility = 'hide';
  this.borderBottomLayer.visibility = 'hide';
  this.borderLeftLayer.visibility = 'hide';
  this.borderLayer.visibility = 'hide';
}
Border.prototype.hide = Border_hide;
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
function ButtonBorder (layer) {
  this.border = new Border (layer, 1, 'white');
  this.border.borderRightColor = this.border.borderBottomColor 
= 'darkgray';
  this.border.updateBorders();
}
function ButtonBorder_show () {
  this.border.show();
}
ButtonBorder.prototype.show = ButtonBorder_show;
function ButtonBorder_hide () {
  this.border.hide();
}
ButtonBorder.prototype.hide = ButtonBorder_hide; 
function ButtonBorder_press () {
  this.border.borderTopColor = this.border.borderLeftColor 
= 'darkgray';
  this.border.borderBottomColor = this.border.borderRightColor 
= 'white';
  this.border.updateBorders();
}
ButtonBorder.prototype.press = ButtonBorder_press;
function ButtonBorder_unPress () {
  this.border.borderTopColor = this.border.borderLeftColor = 'white';
  this.border.borderBottomColor = this.border.borderRightColor 
= 'darkgray';
  this.border.updateBorders();
}
ButtonBorder.prototype.unPress = ButtonBorder_unPress;
</SCRIPT>
<SCRIPT>
function init () {
var l1 = document.button1;
var l2 = document.button2;
l1.onmouseover = l2.onmouseover = function (evt) {
   if (!this.border)
     this.border = new ButtonBorder(this);
   this.border.show();
}
l1.onmouseout = l2.onmouseout = function (evt) {
  this.border.hide();
}
l1.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP );
l2.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP );
l1.onmousedown = l2.onmousedown = function (evt) {
  this.border.press();
}
l1.onmouseup = l2.onmouseup = function (evt) {
  this.border.unPress();
}
}
</SCRIPT>
</HEAD>
<BODY  ONLOAD="init()">
<SPAN ID="aLayer" CLASS="borderable">Kibology for all</SPAN>
<BR>
<A HREF="javascript: var l = document.aLayer; 
         if (!l.border) var b = l.border = new Border (l, 3, 'lime');
         else { l.border.setBorderColor('lime'); 
l.border.setBorderWidth
(3); l.border.updateBorders(); } 
         void 0"
>
show lime border
</A>
|
<A HREF="javascript: var l = document.aLayer; 
         if (!l.border) var b = l.border = new Border (l, 1, 'red');
         else { l.border.setBorderColor('red'); l.border.setBorderWidth
(1); l.border.updateBorders(); } 
         void 0"
>
show red border
</A>
<DIV ID="buttonBar">
</DIV>
<SPAN ID="button1">
<A CLASS="buttonLink" HREF="javascript: void 0"
   ONCLICK="location.href = 'http://javascript.faqts.com/'; return 
false;"
>
JavaScript Knowledge Base
</A>
</SPAN>
<SPAN ID="button2">
<A CLASS="buttonLink" HREF="javascript: void 0"
   ONCLICK="location.href = 'http://www.faqts.com/'; return false;"
>
General Knowledge Base
</A>
</SPAN>
</BODY>
</HTML>
http://www.jaipurtravelguide.com/
http://www.jaipurtravels.com/
http://www.jaipurjaipur.com/
http://www.jaipurtourismguide.com/
http://www.rajasthantravelsguide.com/
http://www.rajasthantravelguide.co.in/
http://www.travelpackagerajasthan.com/
http://www.namaskarindiatravels.com/
http://www.indianhotelsindia.com/
http://www.travelpackageindia.com/
http://www.navyatravels.com/
http://www.hillstationindiatour.com/
http://www.wildlifeindiatravel.com/ 
http://www.pushkartravels.com/
http://www.udaipurtravels.com/
http://www.agratravels.com/
http://indiantravelguide.co.in/
http://www.traveltoindia.biz/
http://www.info4india.com/
http://www.indiantravelsguide.com/
http://www.indiantravelguideindia.com/
http://rajasthantravelguide.wordpress.com/
http://attractioninjaipur.blogspot.com/
http://jaipurtravelsguide.blogspot.com/
http://hoteles-en-la-india.blogspot.com/
http://jaipurguiadeviajes.blogspot.com/
http://jaipurrajasthanindia.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://travelguiderajasthan.blogspot.com/
http://wildlifeindiatravel.blogspot.com/
http://indiantravelguideindia.blogspot.com/
http://indianhotelsindia.blogspot.com/
http://rajasthantravelsguide.blogspot.com/
http://pushkartravels.blogspot.com/
http://indiatravelsguide.blogspot.com/
http://goaguidedevoyage.blogspot.com/
http://goatravelsguide.blogspot.com/
http://indiaguadeviajes.blogspot.com/
http://htelseninde.blogspot.com/
http://indienguidedevoyage.blogspot.com/
http://indianhillstationsindiatravel.blogspot.com/
http://jaipurtravelguiderajasthan.blogspot.com/
http://hillstationinindia.blogspot.com/
http://jaipurcarrentals.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://indianadventuretourpackages.blogspot.com/
http://rajasthantraintourpackage.blogspot.com/
http://jaipurinformationguide.blogspot.com/
http://rajasthanculturaltourpackages.blogspot.com/
http://uttaranchaltourpackages.blogspot.com/
http://luxurytourspackages.blogspot.com/
http://indiahimalayatourtravelpackages.blogspot.com/
http://eastindiatravelpackages.blogspot.com/
http://indiahillstationstravelpackages.blogspot.com/
http://indiatravelpackages.blogspot.com/
http://westindiatourpackages.blogspot.com/
http://lehladakhtourpackages.blogspot.com/
http://indiabudgettourtravelpackage.blogspot.com/
http://romanticrajasthanhoneymoontour.blogspot.com/
http://worldtravelsguide.blogspot.com/
http://jaipursilverjewellery.com/
http://www.jaipurhandicrafts.com/
http://www.roo7e.com
http://www.roo7e.com
http://www.al33ab.com
http://ksacam.com
http://chat.ksacam.com
http://ksacam.info
http://oo2o.com
http://s4cam.com
http://saudi4cam.com				
http://voice.ksacam.com
http://سعودي-كام.oo2o.com
http://سعوديكام.com
http://xn--mgbply5cnrr.com
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.3rabstarz.com/vb
http://www.3rabstarz.com/
http://www.dir.3rabstarz.com/
http://www.up.3rabstarz.com
http://www.3rabstarz.com/vb/forumdisplay.php?f=5
http://www.3rabstarz.com/vb/forumdisplay.php?f=116
http://www.3rabstarz.com/vb/forumdisplay.php?f=66
http://www.3rabstarz.com/vb/forumdisplay.php?f=78
http://www.3rabstarz.com/vb/forumdisplay.php?f=147
http://www.3rabstarz.com/vb/forumdisplay.php?f=2
http://www.3rabstarz.com/vb/forumdisplay.php?f=31
http://www.3rabstarz.com/vb/forumdisplay.php?f=136
http://www.3rabstarz.com/vb/forumdisplay.php?f=34
http://www.3rabstarz.com/vb/forumdisplay.php?f=89
http://www.3rabstarz.com/vb/forumdisplay.php?f=26
http://www.3rabstarz.com/vb/forumdisplay.php?f=72
http://www.3rabstarz.com/vb/forumdisplay.php?f=73
http://www.3rabstarz.com/vb/forumdisplay.php?f=149
http://www.3rabstarz.com/vb/forumdisplay.php?f=150
http://www.3rabstarz.com/vb/forumdisplay.php?f=151
http://www.3rabstarz.com/vb/forumdisplay.php?f=152
http://www.3rabstarz.com/vb/forumdisplay.php?f=67
http://www.3rabstarz.com/vb/forumdisplay.php?f=3
http://www.3rabstarz.com/vb/forumdisplay.php?f=37
http://www.3rabstarz.com/vb/forumdisplay.php?f=115
http://www.3rabstarz.com/vb/forumdisplay.php?f=76
http://www.3rabstarz.com/vb/forumdisplay.php?f=77
http://www.3rabstarz.com/vb/forumdisplay.php?f=36
http://www.3rabstarz.com/vb/forumdisplay.php?f=153
http://www.3rabstarz.com/vb/forumdisplay.php?f=122
http://www.3rabstarz.com/vb/forumdisplay.php?f=118
http://www.3rabstarz.com/vb/forumdisplay.php?f=119
http://www.3rabstarz.com/vb/forumdisplay.php?f=120
http://www.3rabstarz.com/vb/forumdisplay.php?f=121
http://www.3rabstarz.com/vb/forumdisplay.php?f=35
http://www.3rabstarz.com/vb/forumdisplay.php?f=65
http://www.3rabstarz.com/vb/forumdisplay.php?f=7
http://www.3rabstarz.com/vb/forumdisplay.php?f=9
http://www.3rabstarz.com/vb/forumdisplay.php?f=11
http://www.3rabstarz.com/vb/forumdisplay.php?f=142
http://www.3rabstarz.com/vb/forumdisplay.php?f=143
http://www.3rabstarz.com/vb/forumdisplay.php?f=146
http://www.3rabstarz.com/vb/forumdisplay.php?f=140
http://www.3rabstarz.com/vb/forumdisplay.php?f=137
http://www.3rabstarz.com/vb/forumdisplay.php?f=114
http://www.3rabstarz.com/vb/forumdisplay.php?f=117
http://www.3rabstarz.com/vb/forumdisplay.php?f=113
http://www.3rabstarz.com/vb/forumdisplay.php?f=51
http://www.3rabstarz.com/vb/forumdisplay.php?f=84
http://www.3rabstarz.com/vb/forumdisplay.php?f=138
http://www.3rabstarz.com/vb/forumdisplay.php?f=139
http://www.3rabstarz.com/vb/forumdisplay.php?f=15
http://www.3rabstarz.com/vb/forumdisplay.php?f=130
http://www.3rabstarz.com/vb/forumdisplay.php?f=97
http://www.3rabstarz.com/vb/forumdisplay.php?f=102
http://www.3rabstarz.com/vb/forumdisplay.php?f=101
http://www.3rabstarz.com/vb/forumdisplay.php?f=104
http://www.3rabstarz.com/vb/forumdisplay.php?f=131
http://www.3rabstarz.com/vb/forumdisplay.php?f=103
http://www.3rabstarz.com/vb/forumdisplay.php?f=99
http://www.3rabstarz.com/vb/forumdisplay.php?f=59
http://www.3rabstarz.com/vb/forumdisplay.php?f=60
http://www.3rabstarz.com/vb/forumdisplay.php?f=39
http://www.3rabstarz.com/vb/forumdisplay.php?f=40
http://www.3rabstarz.com/vb/forumdisplay.php?f=42
http://www.3rabstarz.com/vb/forumdisplay.php?f=4
http://www.3rabstarz.com/vb/forumdisplay.php?f=1
http://www.3rabstarz.com/vb/forumdisplay.php?f=88
http://www.3rabstarz.com/vb/forumdisplay.php?f=148
http://www.3rabstarz.com/vb/forumdisplay.php?f=62
http://www.3rabstarz.com/vb/forumdisplay.php?f=63
http://www.3rabstarz.com/vb/forumdisplay.php?f=64
http://www.3rabstarz.com/vb/forumdisplay.php?f=6
http://www.3rabstarz.com/vb/forumdisplay.php?f=12
http://www.3rabstarz.com/vb/forumdisplay.php?f=96
http://www.3rabstarz.com/vb/forumdisplay.php?f=58
http://www.3rabstarz.com/vb/forumdisplay.php?f=38