View Full Version : Help - Image tooltip

03-14-2006, 12:25 AM
Hey there im trying to do this here http://www.dynamicdrive.com/dynamicindex4/imagetooltip.htm

Can anyone help me and see if i have any errors because the image isnt showing up but if i do it on a blank page it does, is it something to do with my previous code. Anyhow ill shut up and post the code so you can all see.

Unformated code removed. See below.

03-14-2006, 05:54 AM
Your code is unlikely to be able to be easily restored from your post after the editor has wrapped it. Either supply a link to the page (best), attach a file, or use
tags as explained here (http://www.dynamicdrive.com/forums/misc.php?do=bbcode#code) around your code so that it will look like so:

Your code here

03-14-2006, 09:02 AM
Hey there im trying to do this here http://www.dynamicdrive.com/dynamicindex4/imagetooltip.htm

Can anyone help me and see if i have any errors because the image isnt showing up but if i do it on a blank page it does, is it something to do with my previous code. Anyhow ill shut up and post the code so you can all see.

Also the website has been hosted at www.shadows-clan.co.uk.


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Prosperity a World of Warcraft guild website</title>

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="scroll.css">
<script language="JavaScript">
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

<script language="javascript" type="text/javascript">

Image w/ description tooltip- By Dynamic Web Coding (www.dyn-web.com)
Copyright 2002 by Sharon Paine
Visit http://www.dynamicdrive.com for this script

/* IMPORTANT: Put script after tooltip div or
put tooltip div just before </BODY>. */

var dom = (document.getElementById) ? true : false;
var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
var ns4 = (document.layers && !dom) ? true : false;
var ie4 = (document.all && !dom) ? true : false;
var nodyn = (!ns5 && !ns4 && !ie4 && !ie5) ? true : false;

// resize fix for ns4
var origWidth, origHeight;
if (ns4) {
origWidth = window.innerWidth; origHeight = window.innerHeight;
window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }

// avoid error of passing event object in older browsers
if (nodyn) { event = "nope" }

/////////////////////// CUSTOMIZE HERE ////////////////////
// settings for tooltip
// Do you want tip to move when mouse moves over link?
var tipFollowMouse= true;
// Be sure to set tipWidth wide enough for widest image
var tipWidth= 372;
var offX= 20; // how far from mouse to show tip
var offY= 12;
var tipFontFamily= "Verdana, arial, helvetica, sans-serif";
var tipFontSize= "8pt";
// set default text color and background color for tooltip here
// individual tooltips can have their own (set in messages arrays)
// but don't have to
var tipFontColor= "#6600CC";
var tipBgColor= "#333333";
var tipBorderColor= "#333333";
var tipBorderWidth= 3;
var tipBorderStyle= "ridge";
var tipPadding= 4;

// tooltip content goes here (image, description, optional bgColor, optional textcolor)
var messages = new Array();
// multi-dimensional arrays containing:
// image and text for tooltip
// optional: bgColor and color to be sent to tooltip
messages[0] = new Array('neo.gif,','Here is a duck on a light blue background.',"#DDECFF");
messages[1] = new Array('hobf.gif','Here is a duck on a light blue background.',"#DDECFF");
messages[2] = new Array('botem.gif','Here is a duck on a light blue background.',"#DDECFF");

//////////////////// END OF CUSTOMIZATION AREA ///////////////////

// preload images that are to appear in tooltip
// from arrays above
if (document.images) {
var theImgs = new Array();
for (var i=0; i<messages.length; i++) {
theImgs[i] = new Image();
theImgs[i].src = messages[i][0];

// to layout image and text, 2-row table, image centered in top cell
// these go in var tip in doTooltip function
// startStr goes before image, midStr goes between image and text
var startStr = '<table width="' + tipWidth + '"><tr><td align="center" width="100%"><img src="';
var midStr = '" border="0"></td></tr><tr><td valign="top">';
var endStr = '</td></tr></table>';

// initTip - initialization for tooltip.
// Global variables for tooltip.
// Set styles for all but ns4.
// Set up mousemove capture if tipFollowMouse set true.
var tooltip, tipcss;
function initTip() {
if (nodyn) return;
tooltip = (ns4)? document.tipDiv.document: (ie4)? document.all['tipDiv']: (ie5||ns5)? document.getElementById('tipDiv'): null;
tipcss = (ns4)? document.tipDiv: tooltip.style;
if (ie4||ie5||ns5) { // ns4 would lose all this on rewrites
tipcss.width = tipWidth+"px";
tipcss.fontFamily = tipFontFamily;
tipcss.fontSize = tipFontSize;
tipcss.color = tipFontColor;
tipcss.backgroundColor = tipBgColor;
tipcss.borderColor = tipBorderColor;
tipcss.borderWidth = tipBorderWidth+"px";
tipcss.padding = tipPadding+"px";
tipcss.borderStyle = tipBorderStyle;
if (tooltip&&tipFollowMouse) {
if (ns4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = trackMouse;

window.onload = initTip;

// doTooltip function
// Assembles content for tooltip and writes
// it to tipDiv
var t1,t2; // for setTimeouts
var tipOn = false; // check if over tooltip link
function doTooltip(evt,num) {
if (!tooltip) return;
if (t1) clearTimeout(t1); if (t2) clearTimeout(t2);
tipOn = true;
// set colors if included in messages array
if (messages[num][2]) var curBgColor = messages[num][2];
else curBgColor = tipBgColor;
if (messages[num][3]) var curFontColor = messages[num][3];
else curFontColor = tipFontColor;
if (ns4) {
var tip = '<table bgcolor="' + tipBorderColor + '" width="' + tipWidth + '" cellspacing="0" cellpadding="' + tipBorderWidth + '" border="0"><tr><td><table bgcolor="' + curBgColor + '" width="100%" cellspacing="0" cellpadding="' + tipPadding + '" border="0"><tr><td>'+ startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr + '</td></tr></table></td></tr></table>';
} else if (ie4||ie5||ns5) {
var tip = startStr + messages[num][0] + midStr + '<span style="font-family:' + tipFontFamily + '; font-size:' + tipFontSize + '; color:' + curFontColor + ';">' + messages[num][1] + '</span>' + endStr;
tipcss.backgroundColor = curBgColor;
tooltip.innerHTML = tip;
if (!tipFollowMouse) positionTip(evt);
else t1=setTimeout("tipcss.visibility='visible'",100);

var mouseX, mouseY;
function trackMouse(evt) {
mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
if (tipOn) positionTip(evt);

// positionTip function
// If tipFollowMouse set false, so trackMouse function
// not being used, get position of mouseover event.
// Calculations use mouseover event position,
// offset amounts and tooltip width to position
// tooltip within window.
function positionTip(evt) {
if (!tipFollowMouse) {
mouseX = (ns4||ns5)? evt.pageX: window.event.clientX + document.body.scrollLeft;
mouseY = (ns4||ns5)? evt.pageY: window.event.clientY + document.body.scrollTop;
// tooltip width and height
var tpWd = (ns4)? tooltip.width: (ie4||ie5)? tooltip.clientWidth: tooltip.offsetWidth;
var tpHt = (ns4)? tooltip.height: (ie4||ie5)? tooltip.clientHeight: tooltip.offsetHeight;
// document area in view (subtract scrollbar width for ns)
var winWd = (ns4||ns5)? window.innerWidth-20+window.pageXOffset: document.body.clientWidth+document.body.scrollLeft;
var winHt = (ns4||ns5)? window.innerHeight-20+window.pageYOffset: document.body.clientHeight+document.body.scrollTop;
// check mouse position against tip and window dimensions
// and position the tooltip
if ((mouseX+offX+tpWd)>winWd)
tipcss.left = (ns4)? mouseX-(tpWd+offX): mouseX-(tpWd+offX)+"px";
else tipcss.left = (ns4)? mouseX+offX: mouseX+offX+"px";
if ((mouseY+offY+tpHt)>winHt)
tipcss.top = (ns4)? winHt-(tpHt+offY): winHt-(tpHt+offY)+"px";
else tipcss.top = (ns4)? mouseY+offY: mouseY+offY+"px";
if (!tipFollowMouse) t1=setTimeout("tipcss.visibility='visible'",100);

function hideTip() {
if (!tooltip) return;
tipOn = false;


03-14-2006, 09:03 AM
<body bgcolor="#000000" onLoad="MM_preloadImages('menudownloadsroll.gif','menuhomeroll.gif','menuforumsroll.gif','menuscreenshotsroll.gif','menulinksroll.gif','menumemberroll.gif')" link="#9900FF">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="760">
<td width="760"><img border="0" src="topleft.gif" width="280" height="67"><img border="0" src="topmiddle.gif" width="333" height="67"><img border="0" src="topright.gif" width="147" height="67"></td>
<td width="760"><img border="0" src="middleleft.gif" width="220" height="128"><img border="0" src="middlemiddle.gif" width="320" height="128"><img border="0" src="middleright.gif" width="220" height="128"></td>

<td width="760" background="menubg.gif"><a href="http://www.shadows-clan.co.uk/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image19','','menuhomeroll.gif',1)"><img name="Image19" border="0" src="menuhome.gif" width="52" height="26"></a><a href="http://www.shadows-clan.co.uk/members.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image20','','menumemberroll.gif',1)"><img name="Image20" border="0" src="menumember.gif" width="85" height="26"></a><a href="http://www.shadows-clan.co.uk/downloads.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image21','','menudownloadsroll.gif',1)"><img name="Image21" border="0" src="menudownloads.gif" width="79" height="26"></a><a href="http://www.shadows-clan.co.uk/forum.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image22','','menuforumsroll.gif',1)"><img src="blank3.gif" width="13" height="26" border="0"><img name="Image22" border="0" src="menuforums.gif" width="55" height="26"><img src="blank3.gif" width="13" height="26" border="0"></a><a href="http://www.shadows-clan.co.uk/screenshots.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image24','','menuscreenshotsroll.gif',1)"><img name="Image24" border="0" src="menuscreenshots.gif" width="85" height="26"><img src="blank3.gif" width="13" height="26" border="0"></a><a href="http://www.shadows-clan.co.uk/links.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image23','','menulinksroll.gif',1)"><img name="Image23" border="0" src="menulinks.gif" width="45" height="26"></a><img src="blank2.gif" width="49" height="26"><img border="0" src="menuright.gif" width="271" height="26"></td>
<td width="760"><img border="0" src="bottomleft.gif" width="255" height="45"><img border="0" src="bottommiddle.gif" width="284" height="45"><img border="0" src="bottomright.gif" width="221" height="45"></td>

<td width="761" background="borders.gif" bgcolor="#FFFFCC"> &nbsp;
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="90%">

<td width="100%">
<table border="1" cellpadding="0" cellspacing="7" width="100%" bgcolor="#FFFF99" height="223" bordercolor="#996600">
<tr bordercolor="#000000">
<td width="63%" valign="top" bgcolor="#FFFF99" height="34" bordercolor="#996600">
<p align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>The
dirty green biatch Emeriss is dead!<br>
</b>Monday 13th March 2006</font></p>
<td width="37%" valign="top" bgcolor="#FFFF99" height="34" bordercolor="#996600">
<p align="center"><font size="1" color="#000000"><b><font face="Verdana, Arial, Helvetica, sans-serif">Screenshot</font></b></font></p>
<tr bordercolor="#000000">
<td width="63%" valign="top" bgcolor="#FFFF99" bordercolor="#996600"><font face="Verdana, Arial, Helvetica, sans-serif" size="1">In
recent times, Ysera's most trusted lieutenants have been
warped by a dark new power within the Emerald Dream. Now
these wayward sentinels have passed through the Great
Trees into Azeroth, intending to spread madness and terror
throughout the mortal kingdoms. </font>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1">The
mysterious dark power within the Emerald Dream has transformed
the once-majestic Emeriss into a rotting, disease<font color="#000000">d
monstrosity. Reports from the few who have survived
encounters with<font face="Arial, Helvetica, sans-serif">
the dragon have told horrifying tales of putrid mushrooms
erupting from the corpses of the</font>ir dead com</font>panions.
Emeriss is truly the most gruesome and appalling of
Ysera's estranged green dragons. <br>
<p><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><br>
<a href="#" onMouseOver="doTooltip(event,0)" onMouseOut="hideTip()">Link
<a href="#" onMouseOver="doTooltip(event,1)" onMouseOut="hideTip()">Link
2</a> </b> </font></p>
<td width="37%" valign="top" bgcolor="#FFFF99" bordercolor="#996600">
<div align="center"></div>
<td width="761"><img border="0" src="bottom.gif" width="760" height="1"></td>
<p align="center"><font color="#FFCC00" size="1" face="Verdana, Arial, Helvetica, sans-serif">&copy;2006
Hauxen Designs. All rights reserved.</font><font color="#FFFF99" size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<div id="tipDiv" style="position:absolute; visibility:hidden; z-index:100"></div>


03-14-2006, 04:47 PM
You have a script conflict between your image preload script and the tool tip script. To resolve that, remove this from the tool tip script:

window.onload = initTip;

and make your body tag look like so (addition red):

<body bgcolor="#000000" onLoad="initTip();MM_preloadImages('menudownloadsroll.gif','menuhomeroll.gif','menuforumsroll.gif','menuscreenshotsroll.gif','menulinksroll.gif','menumemberroll.gif')" link="#FFFF99">

There could be other problems but, this needs to be fixed first, it may be all that is needed to fix it.

03-14-2006, 04:57 PM
I found another problem, your arrays:

messages[0] = new Array('neo.gif,);
messages[1] = new Array('hobf.gif,);
messages[2] = new Array('botem.gif,);

should look like this:

messages[0] = new Array('neo.gif','');
messages[1] = new Array('hobf.gif','');
messages[2] = new Array('botem.gif','');

03-14-2006, 05:20 PM
Thanks, ill check it when i get home and keep you updated.