PDA

View Full Version : mouse over + table cells


g00fy
01-29-2003, 11:18 PM
hello all,

i found a tutorial early last year that showed you how to change a picture inside a table cell when you mouseover another cell, but i cannot find it anywhere now that i would like to do something like this :(

can anyone guide me in the right direction or offer some code that i can get going with, i can code java and am slowing getting my head around JScript
(i could use a applet but js is easier to update, and would load faster)

what i want to do is have a central picture inside the middle cell of a table and nav links around it, which on rollover change the central pic.


TIA,

G00fy

chrismiceli
01-30-2003, 12:01 AM
just give the picture an id, an put on any td this.
<td onMouseOver="document.getElementById('whatever').src='whatever.jpg'" onMouseOut="document.getElementsById('whatever').src='oldwhatever.jpg'">
where whatever is the id you gave the pic.

g00fy
01-30-2003, 01:05 AM
thanx heaps,

i didnt know about the getElementById method, but now i do :thumbsup:


g00fy

g00fy
01-30-2003, 04:24 AM
chrismiceli,

i have just tried this but i cant get it to work :(, i cant figure out how to give more than one picture an id if its in the same cell, i.e., you dont see the other pic until mouseover

see code below pls:


<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%"><div align="center"></div></td>
<td width="34%">&nbsp;</td>
<td width="33%">&nbsp;</td>
</tr>
<tr>
<td onMouseOver="document.getElementById('mad_big').src='images/mad.gif'" onMouseOut="document.getElementsById('mad_small').src='images/mad_small.gif'">Test</td>
<td rowspan="4"><div align="center"><img src="images/mad.gif" width="220" height="99" id="mad_big"></div></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="center"></div></td>
<td>&nbsp;</td>
</tr>
.
.
.


in IE i get error: object doesnt support this method or property

TIA

g00fy

Roy Sinclair
01-30-2003, 07:00 PM
<td onMouseOver="document.getElementById('mad_big').src='images/mad.gif'" onMouseOut="document.getElementsById('mad_big').src='images/mad_small.gif'">Test</td>


Swapping the image doesn't change the ID of the image tag.

g00fy
01-30-2003, 11:55 PM
thanx all,

i appreciate the help

i cant get the image to return onmouseout :(

also is there a way to set the image size, cause it expands to fill the whole <div>


<tr>
<td align="center" onMouseOver="document.getElementById('mad_big').src='images/icons/home.gif'" onMouseOut="document.getElementsById('mad_big').src='images/mad.gif'">Test</td>

<td rowspan="4"><div align="center"><img src="images/mad.gif" width="220" height="99" id="mad_big"></div></td>


thanx again

g00fy

g00fy
01-31-2003, 12:25 PM
sorry to nag,

but i worked out the onmouseout => it needed document.getElementById and not document.getElementsById

(that was just to make me work it out wasn't it) :thumbsup:

is there a way though to set image size or do i just resize all my images that will be in that <div> ?


thanx again

g00fy

Wally Gator
02-02-2003, 08:34 PM
Hi
I can't seem to get the mouseover menu to close
when cusor moves out od link frame.

Here is the code I have used. Where is the problem?

<div id="popmenu" class="menuskin" onMouseover="clearhidemenu();highlightmenu(event,'on')" onMouseout="status=' ';highlightmenu(event,'off');dynamichide(event)">
</div>
<body link="white"><font color="yellow">* * * * * * *
<a href="#" onmouseover="showmenu(event,linkset[0])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">League Schedule</a> <font color="yellow">* * * * * * *
<a href="#" onMouseover="showmenu(event,linkset[1])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">Division Directors</a> <font color="yellow">* * * * * * *
<a href="#" onMouseover="showmenu(event,linkset[2])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">Teams</a> <font color="yellow">* * * * * * *
<a href="fields.htm" style="text-decoration:none"><font color="white">Fields<a> <font color="yellow">* * * * * * * * * * * </font>

g00fy
02-02-2003, 11:02 PM
can u post your jscript methods code ?


regards,

g00fy

Wally Gator
02-03-2003, 01:07 AM
Hi
I can't seem to get the mouseover menu to close
when cusor moves out of link frame.


website url using java script in ? at

http://ksd77.com/Fall.htm


Here is the code I have used. Where is the problem?
sorry for the size

<style>
<!--

.menuskin{
position:absolute;
width:165px;
background-color:menu;
border:2px solid black;
font:normal 12px Verdana;
line-height:18px;
z-index:100;
visibility:hidden;
}

.menuskin a{
text-decoration:none;
color:black;
padding-left:10px;
padding-right:10px;
}

#mouseoverstyle{
background-color:highlight;
}

#mouseoverstyle a{
color:white;
}
-->
</style>

<script language="JavaScript1.2">

//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<div class="menuitems"><a href="U6schedule.htm">U 6 Instructional</a></div>'
linkset[0]+='<div class="menuitems"><a href="U8&U10schedule.htm">U 8 & U 10</a></div>'
linkset[0]+='<div class="menuitems"><a href="U12&U15schedule.htm">U 12 & U 15 </a></div>'

linkset[1]='<div class="menuitems"><a href="U6.htm">U 6</a></div>'
linkset[1]+='<div class="menuitems"><a href="U8B.htm">U 8 B</a></div>'
linkset[1]+='<div class="menuitems"><a href="U8G.htm">U 8 G</a></div>'
linkset[1]+='<div class="menuitems"><a href="U10B.htm">U 10 B</a></div>'
linkset[1]+='<div class="menuitems"><a href="U10G.htm">U 10 G</a></div>'
linkset[1]+='<div class="menuitems"><a href="U12B.htm">U 12 B</a></div>'
linkset[1]+='<div class="menuitems"><a href="U12G.htm">U 12 G</a></div>'
linkset[1]+='<div class="menuitems"><a href="U15B.htm">U 15 B</a></div>'
linkset[1]+='<div class="menuitems"><a href="U15G.htm">U 15 G</a></div>'

linkset[2]='<div class="menuitems"><a href="1.htm">Team 1</a></div>'
linkset[2]+='<div class="menuitems"><a href="2.htm">Team 2</a></div>'
linkset[2]+='<div class="menuitems"><a href="3.htm">Team 3</a></div>'
linkset[2]+='<div class="menuitems"><a href="4.htm">Team 4</a></div>'
linkset[2]+='<div class="menuitems"><a href="5.htm">Team 5</a></div>'
linkset[2]+='<div class="menuitems"><a href="6.htm">Team 6</a></div>'
linkset[2]+='<div class="menuitems"><a href="7.htm">Team 7</a></div>'
linkset[2]+='<div class="menuitems"><a href="8.htm">Team 8</a></div>'
linkset[2]+='<div class="menuitems"><a href="68.htm">Team 68</a></div>'
////No need to edit beyond here

var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=60 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX

//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}

if (ie4||ns6)
document.onclick=hidemenu

</script>
<div id="popmenu" class="menuskin" onMouseover="clearhidemenu();highlightmenu(event,'on')" onMouseout="status=' ';highlightmenu(event,'off');dynamichide(event)">
</div>
<body link="white"><font color="yellow">* * * * * * *
<a href="#" onmouseover="showmenu(event,linkset[0])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">League Schedule</a> <font color="yellow">* * * * * * *
<a href="#" onMouseover="showmenu(event,linkset[1])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">Division Directors</a> <font color="yellow">* * * * * * *
<a href="#" onMouseover="showmenu(event,linkset[2])" onMouseout="delayhidemenu()"style="text-decoration:none"><font color="white">Teams</a> <font color="yellow">* * * * * * *
<a href="fields.htm" style="text-decoration:none"><font color="white">Fields<a> <font color="yellow">* * * * * * * * * * * </font>