Entry
How can I have dynamic borders with layers in NN4?
How to build buttons with NN4?
Nov 22nd, 2008 02:14
Raj Aryan, Martin Honnen,
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.webs4soft.com/Links4.htm
http://hotelsinindia.webs4soft.com/hotels-in-delhi.htm
http://indiatravel.webs4soft.com/Resources.htm
http://indianmovies.webs4soft.com/Kuch-Kuch-Hota-Hai.htm
http://real-estate.webs4soft.com/property-tips.htm
http://foodhealthcaretips.webs4soft.com/Resources.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://indianjewelry.websitecompanyindia.com/dimond-ring.htm
http://www.bestindiaeducation.com/Link-Exchange.htm
http://bestjobconsultant.bestindiaeducation.com/PARTNERS.htm
http://eloctronicandmobilestore.bestindiaeducation.com/mobile-links.htm
http://easyloanservice.bestindiaeducation.com/Home-Insurance-Links.htm
http://www.rajhealthcenter.com/Cosmetic-Surgery.htm
http://creativebusinessgroup.rajhealthcenter.com/Business-Links.htm
http://onlinefreeinternetgames.rajhealthcenter.com/Games-Links.htm
http://top-beauty-tips.rajhealthcenter.com/Beauty-Links.htm
http://www.indiatourpoint.com/Travel-Links.htm
http://four-wheeler-buy-tips.indiatourpoint.com/Auto-Links.htm
http://watch-online-free-cricket-match.indiatourpoint.com/Sports-Links.htm
http://directory.indiatourpoint.com/
http://www.bestlifeindia.com/Resources1.htm
http://directory.bestlifeindia.com/
http://freeorkutscrapandsms.bestlifeindia.com/SMS-Links.htm
http://onlinegiftshop.bestlifeindia.com/Gift-Links.htm
http://www.freemusicpoint.com/Music-Links.htm
http://love-dating.freemusicpoint.com
http://online-art-presentation.freemusicpoint.com/
http://onlinefurnitureshop.freemusicpoint.com/