PDA

View Full Version : CSS + JavaScript Menu problems


AlexV
06-25-2007, 02:38 PM
Hello!

I have a menu up here http://www.wolfcast.com/menuc/

I have a bug in Opera & Safari on Windows:
http://www.wolfcast.com/menuc/Opera.jpg (last letter of each word is 'chopped' on poping menus)
http://www.wolfcast.com/menuc/Safari.jpg (main items not showing up)

I want to fix them.

I also want to simplify all that CSS/HTML code, but this is my first real use of CSS...

I know I should not use tables, and are willing to replace it by something else but I don't know how.

Anyone is willing to help ?

kosstr12
06-25-2007, 02:52 PM
Please List Your CSS, and Javascript

AlexV
06-25-2007, 02:57 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/strict.dtd">
<!-- saved from url=(0023)http://www.wolfcast.com -->
<html lang="EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Wolfcast</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="Wolfcast / Alexandre Valiquette">

<script type="text/javascript" src="ypSlideOutMenus.js"></script>
<script type="text/javascript">
var myMenu1 = new ypSlideOutMenu("menu1", "down", -4, 4, 125, 50);
var myMenu2 = new ypSlideOutMenu("menu2", "down", -4, 4, 170, 50);
var myMenu3 = new ypSlideOutMenu("menu3", "down", -4, 4, 245, 100);
var myMenu6 = new ypSlideOutMenu("menu6", "down", -4, 4, 125, 75);
var myMenu7 = new ypSlideOutMenu("menu7", "down", -4, 4, 130, 75);

ypSlideOutMenu.writeCSS();
</script>

<STYLE type="text/css">

body {
background-color : white;
font-family : "Segoe UI", Tahoma, Geneva, Verdana, Arial, Helvetica;
font-size : 12px;
margin : 0;
padding : 0;
}

.menuactuator a:hover {
color : rgb(34,113,150);
}

.menubar {
background-attachment : scroll;
background-color : white;
background-image : url('MenuGradient.gif');
background-position : bottom;
background-repeat : repeat-x;
border : 1px solid rgb(71,150,183);
height : 22px;
margin : auto;
text-align : center;
width : 850px;
}

.menubar a { /* root menu items */
color : rgb(9,88,125);
display : block;
font-weight : bold;
letter-spacing : 1px;
text-decoration : none;
}

.menubar td {
border-right : 1px solid rgb(71,150,183);
cursor : pointer;
}

.menubar td div { /* this makes TDs a container with their own coordinate system. absolutely-positioned elements will be offset relative to them */
position : relative;
text-align : left;
}

.menu a { /* sub-menu items */
border: solid 1px rgb(248,251,252);
display : block;
font-weight : normal;
padding : 2px 10px;
}

.menu a:hover {
background-color : rgb(101,196,233);
border: solid 1px rgb(71,150,183);
color : white;
display : block;
}

.menu .options { /* sub-menu items box */
background-color : rgb(248,251,252);
border : 1px solid rgb(71,150,183);
border-top : none;
padding : 1px;
}

.transp95 {
/*-moz-opacity : 0.95; /* depreciated */
filter : alpha(opacity=95); /* IE */
opacity : 0.95; /* CSS3 */
}

</style>

</head>
<body>


<table class="menubar" border="0">
<tr>
<td class="menuactuator" onclick="window.location='/';" onmouseout="ypSlideOutMenu.hideMenu('menu1');" onmouseover="ypSlideOutMenu.showMenu('menu1');">
<a href="/">Home</a>
<div>
<div class="transp95" id="menu1Container">
<div class="menu" id="menu1Content">
<div class="options" style="width : 121px;">
<a href="/">Current news</a>
<a href="oldnews.php">Old news</a>
</div>
</div>
</div>
</div>
</td>

<td class="menuactuator" onclick="window.location='products.php';" onmouseout="ypSlideOutMenu.hideMenu('menu2');" onmouseover="ypSlideOutMenu.showMenu('menu2');">
<a href="products.php">Products</a>
<div>
<div class="transp95" id="menu2Container">
<div class="menu" id="menu2Content">
<div class="options" style="width : 166px;">
<a href="collectiontracker.php">Collection Tracker</a>
<a href="opensource.php">Open source projects</a>
</div>
</div>
</div>
</div>
</td>

<td class="menuactuator" onclick="window.location='services.php';" onmouseout="ypSlideOutMenu.hideMenu('menu3');" onmouseover="ypSlideOutMenu.showMenu('menu3');">
<a href="services.php">Services</a>
<div>
<div class="transp95" id="menu3Container">
<div class="menu" id="menu3Content">
<div class="options" style="width : 241px;">
<a href="illustration.php">Illustration</a>
<a href="music.php">Music composition</a>
<a href="web.php">Web solutions</a>
<a href="development.php">Windows&trade; based development</a>
</div>
</div>
</div>
</div>
</td>

<td class="menuactuator" onclick="window.location='/download';">
<a href="/download">Download</a>
</td>

<td class="menuactuator" onclick="window.location='catalog.php';">
<a href="catalog.php" >Order</a>
</td>

<td class="menuactuator" onclick="window.location='support.php';" onmouseout="ypSlideOutMenu.hideMenu('menu6');" onmouseover="ypSlideOutMenu.showMenu('menu6');">
<a href="support.php">Support</a>
<div>
<div class="transp95" id="menu6Container">
<div class="menu" id="menu6Content">
<div class="options" style="width : 121px;">
<a href="/forum">Forum</a>
<a href="/livehelp">Live help</a>
<a href="contact.php">Email support</a>
</div>
</div>
</div>
</div>
</td>

<td class="menuactuator" onclick="window.location='cie.php';" onmouseout="ypSlideOutMenu.hideMenu('menu7');" onmouseover="ypSlideOutMenu.showMenu('menu7');">
<a href="cie.php">Company</a>
<div>
<div class="transp95" id="menu7Container">
<div class="menu" id="menu7Content">
<div class="options" style="width : 126px;">
<a href="cie.php">About Wolfcast</a>
<a href="contact.php">Contact us</a>
<a href="links.php">Links</a>
</div>
</div>
</div>
</div>
</td>

<td class="menuactuator" style="border : 0;" onclick="window.location='/forum';">
<a href="/forum" >Community</a>
</td>
</tr>
</table>


</body>
</html>

AlexV
06-25-2007, 02:58 PM
The JavaScript can be downloaded from http://ypslideoutmenus.sourceforge.net

but here it is:

/*****************************************************
* ypSlideOutMenu
* http://ypslideoutmenus.sourceforge.net/
* 3/04/2001
*
* a nice little script to create exclusive, slide-out
* menus for ns4, ns6, mozilla, opera, ie4, ie5 on
* mac and win32. I've got no linux or unix to test on but
* it should(?) work...
*
* Licensed under AFL 2.0
* http://www.opensource.org/licenses/afl-2.0.php
*
* Revised:
* - 08/29/2002 : added .hideAll()
* - 04/15/2004 : added .writeCSS() to support more
* than 30 menus.
* - 03/15/2005 : check if submenu exists -by DuDDo-
* - 06/19/2007 : fixed CSS clip -by A. Valiquette-
*
* --youngpup--
*****************************************************/

ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 500 //default = 1000
ypSlideOutMenu.minCPUResolution = 10

// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
this.ie = document.all ? 1 : 0
this.ns4 = document.layers ? 1 : 0
this.dom = document.getElementById ? 1 : 0
this.css = "";

if (this.ie || this.ns4 || this.dom) {
this.id = id
this.dir = dir
this.orientation = dir == "left" || dir == "right" ? "h" : "v"
this.dirType = dir == "right" || dir == "down" ? "-" : "+"
this.dim = this.orientation == "h" ? width : height
this.hideTimer = false
this.aniTimer = false
this.open = false
this.over = false
this.startTime = 0

// global reference to this object
this.gRef = "ypSlideOutMenu_"+id
eval(this.gRef+"=this")

// add this menu object to an internal list of all menus
ypSlideOutMenu.Registry[id] = this

var d = document

var strCSS = "";
strCSS += '#' + this.id + 'Container { visibility:hidden; '
strCSS += 'left:' + left + 'px; '
strCSS += 'top:' + top + 'px; '
strCSS += 'overflow:hidden; z-index:10000; }'
strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
strCSS += 'width:' + width + 'px; '
strCSS += 'height:' + height + 'px; '
strCSS += 'clip:rect(0 ' + width + 'px ' + height + 'px 0); '
strCSS += '}'

this.css = strCSS;

this.load()
}
}

ypSlideOutMenu.writeCSS = function() {
document.writeln('<style type="text/css">');

for (var id in ypSlideOutMenu.Registry) {
document.writeln(ypSlideOutMenu.Registry[id].css);
}

document.writeln('</style>');
}

ypSlideOutMenu.prototype.load = function() {
var d = document
var lyrId1 = this.id + "Container"
var lyrId2 = this.id + "Content"
var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]
if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)
var temp

if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
else {
this.container = obj1
this.menu = obj2
this.style = this.ns4 ? this.menu : this.menu.style
this.homePos = eval("0" + this.dirType + this.dim)
this.outPos = 0
this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen

// set event handlers.
if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

//set initial state
this.endSlide()
}
}

ypSlideOutMenu.showMenu = function(id)
{
var reg = ypSlideOutMenu.Registry
var obj = ypSlideOutMenu.Registry[id]

if (obj) {
if (obj.container) {
obj.over = true

// close other menus.
for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)

// if this menu is scheduled to close, cancel it.
if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

// if this menu is closed, open it.
if (!obj.open && !obj.aniTimer) reg[id].startSlide(true)
}
}
}

ypSlideOutMenu.hideMenu = function(id)
{
// schedules the menu to close after <hideDelay> ms, which
// gives the user time to cancel the action if they accidentally moused out
var obj = ypSlideOutMenu.Registry[id]
if (obj) {
if (obj.container) {
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
}
}
}

ypSlideOutMenu.hideAll = function()
{
var reg = ypSlideOutMenu.Registry
for (menu in reg) {
ypSlideOutMenu.hide(menu);
if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
}
}

ypSlideOutMenu.hide = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
obj.over = false

if (obj.hideTimer) window.clearTimeout(obj.hideTimer)

// flag that this scheduled event has occured.
obj.hideTimer = 0

// if this menu is open, close it.
if (obj.open && !obj.aniTimer) obj.startSlide(false)
}

ypSlideOutMenu.prototype.startSlide = function(open) {
this[open ? "onactivate" : "ondeactivate"]()
this.open = open
if (open) this.setVisibility(true)
this.startTime = (new Date()).getTime()
this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)
}

ypSlideOutMenu.prototype.slide = function() {
var elapsed = (new Date()).getTime() - this.startTime
if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()
else {
var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)
if (this.open && this.dirType == "-") d = -d
else if (this.open && this.dirType == "+") d = -d
else if (!this.open && this.dirType == "-") d = -this.dim + d
else d = this.dim + d

this.moveTo(d)
}
}

ypSlideOutMenu.prototype.endSlide = function() {
this.aniTimer = window.clearTimeout(this.aniTimer)
this.moveTo(this.open ? this.outPos : this.homePos)
if (!this.open) this.setVisibility(false)
if ((this.open && !this.over) || (!this.open && this.over)) {
this.startSlide(this.over)
}
}

ypSlideOutMenu.prototype.setVisibility = function(bShow) {
var s = this.ns4 ? this.container : this.container.style
s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) {
this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
return parseInt(this.style[c])
}

// events
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }