| Coding Forum Problems with your code? Let's hear about it. |
03-05-2004, 02:57 PM
|
#1 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
Text to appear somewhere on rollover
I want some text to appear in another area on the site when you roll over an image. How would I do this?
I want it similar to when you hover over the buttons on http://www.classic63lincoln.com/ but with text appearing not images
I also want to still be able to keep rollover image capabilities as well
If you don't understand what I'm asking I will try and explain it again.
|
|
|
03-05-2004, 03:16 PM
|
#2 (permalink)
|
|
Possible Terrorist
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
|
javascript.... ive seen it before
onHover="javscript:changeImage();"
or something.. never used javascript though sorry I cant helpy any further
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
|
|
|
03-05-2004, 03:17 PM
|
#3 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
That will only do a normal rollover as far as I know though. Basically I want an onmouseover code but this then makes some text appear in another place on the page.
|
|
|
03-05-2004, 03:57 PM
|
#4 (permalink)
|
|
Possible Terrorist
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
|
you gotta have it call a javscript script.. and have that image originally display with it
so like where you want the image you have
<img src="javascript:getImage()"> or something..
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
|
|
|
03-05-2004, 11:59 PM
|
#5 (permalink)
|
|
Inactive
Join Date: 10-13-03
Posts: 275
Latest Blog: None
|
He doesn't want an image to appear. He wants to make text appear somewhere when you mouseover something.
I'm sure that LazyJim has the answer at the top of his head.
I don't however, but I can suggest that you go to a site like javascriptsource.com or dynamicdrive.com where I'm sure that you'll find something useful. 
|
|
|
03-06-2004, 12:57 AM
|
#6 (permalink)
|
|
v7n Mentor
Join Date: 10-11-03
Posts: 1,137
Latest Blog: None
|
[code:1:101ac1d6c7]<script>
var content=new Array()
//change the array below to the text associated with your links Expand or contract the array, depending on how many links you have
content[0]='Any content you want here - with html tags'
content[1]='Ditto'
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers){
appear()
setTimeout("window.onresize=regenerate",450)
}
}
function changetext(whichcontent){
if (document.all||document.getElementById){
cross_el=document.getElementById? document.getElementById("descriptions"):document.a ll.descriptions
cross_el.innerHTML='<font face="Verdana"><small>'+whichcontent+'<font></small>'
}
else if (document.layers){
document.d1.document.d2.document.write('<font face="Verdana"><small>'+whichcontent+'</small></font>')
document.d1.document.d2.document.close()
}
}
function appear(){
document.d1.visibility='show'
}
window.onload=regenerate2
//-->
</script>[/code:1:101ac1d6c7]
Then call it with this..
[code:1:101ac1d6c7]onmouseover="changetext(content[0]); return true;"[/code:1:101ac1d6c7]
in your link code.
|
|
|
03-06-2004, 01:09 AM
|
#7 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
OK I tried this and got the error 'cross_el' is a null object. Also would this make it so that when I hover over an image I get text somewhere else? It looks from my basic javascript knowledge that this would just make text appear on rollover.
|
|
|
03-06-2004, 03:39 AM
|
#8 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
It's not too much of a problem, but the onmouseover event needs to do two things, one solution is to make it call a single function that calls two others:
[code:1:ae3dad24d0]
<script>
function doHoverText(oImg) {
// text changing code here
}
function doHoverImage(oImg) {
// image mouseover code here
}
function doMouseOver(oImg) {
doHoverText(oImg);
doHoverImage(oImg);
}
</script>
<img src="image.gif" onmouseover="doMouseOver(this)" onmouseout="doMouseOut(this)">[/code:1:ae3dad24d0]
Of course I havn't defiend the functions for onmosue out in that script but you get the idea.
I'll bet you need help with the code missing inside the functions now? 
|
|
|
03-06-2004, 03:52 AM
|
#9 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
yeah, I think I do
|
|
|
03-06-2004, 04:26 AM
|
#10 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
lol
ok which one first?
|
|
|
03-06-2004, 04:42 AM
|
#11 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
the one for the text appearing somewhere else
|
|
|
03-06-2004, 04:47 AM
|
#12 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Depends on if you want to store the text in JavaScript, in a hidden HTML layer, or a hidden <input> value?
Plus I gotta go, back later sorry!
(many scripts out there already).
|
|
|
03-06-2004, 04:56 AM
|
#13 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
I think I'll store it in the Javascript unless activating a hidden layer is easier.
|
|
|
03-06-2004, 07:34 AM
|
#14 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
well hide/show layer is easier - but not so good when people don't have CSS enabled browsers.
In JavaScript it gets annoying if it has HTML (including <br>) or quotes (" or ') in it, and also the longer the text is the more effort it is for coding
So we can do it in JavaScript if you want.
|
|
|
03-06-2004, 07:40 AM
|
#15 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
Quote:
|
Originally Posted by LazyJim
well hide/show layer is easier - but not so good when people don't have CSS enabled browsers.
In JavaScript it gets annoying if it has HTML (including <br>) or quotes (" or ') in it, and also the longer the text is the more effort it is for coding
So we can do it in JavaScript if you want.
|
I think I'll go with the hide/show layer thing. It is quite a bit of text that I want to display and without css the site will probably look terrible anyway.
|
|
|
03-06-2004, 08:27 AM
|
#16 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Now find the element (tag) that contains the whole changing part, and duplicate it in position how ever many tiems you need, (and change the text on each copy to whatever it should be).
Give each copy an id: id="changing_layer_1", id="changing_layer_2", id="changing_layer_3"...
Then give them all style="display: none; speak: none;"
... You don't have to use numbers, give them any ID you want just as long as u remember what's what!
|
|
|
03-06-2004, 08:30 AM
|
#17 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
|
OK done that. Does this have to be done to a div tag or can it be done to a td tag as well.
|
|
|
03-06-2004, 08:33 AM
|
#18 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
no do it to a <div>, it's the safest option, and anything with tables is unsafe due to the way browsers handle them.
|
|
|
03-06-2004, 08:54 AM
|
#19 (permalink)
|
|
Moderator
Join Date: 10-13-03
Location: UK
Posts: 2,819
Latest Blog: None
|
Ok I've changed my mind on a small thing!
Take out the style="display: none; speak: none;" and instead put in class="hidden_layer";
Then set up a style sheet that hides/shows layer that have the right class...
[code:1:641c766e0e]<style>
div.hidden_layer {
display: none;
speak: none;
}
div.visible_layer {
display: block;
speak: normal; /* EDIT: I changed this line after I posted the script */
}
/* You could add more things to hide the layers in old or wierd browsers! Like height: 0px; and visibility: hidden; */
</style>[/code:1:641c766e0e]
And this is the text changing function:
[code:1:641c766e0e]function doHoverText(sID) {
// hide some layers and show the one we want...
// sID is the ID of the layer we want to show.
// If no ID given, bail out:
if (!sID) return;
// Get a reference to the actuall layer:
var oLayer = document.getElementById(sID);
// But bail out if the layer was not found:
if (!oLayer || oLayer=='undefined') return;
// Hide ALL of the layers:
document.getElementById('changing_layer_1').class = "hidden_layer";
document.getElementById('changing_layer_2').class = "hidden_layer";
document.getElementById('changing_layer_3').class = "hidden_layer";
// ...etc. (Note we did not check if the exist, so make sure you don't do a typo, and that the layers ARE there!)
// Then show the layer we want:
oLayer.class = "visible_layer";
}
[/code:1:641c766e0e]
All untested 
|
|
|
03-06-2004, 08:55 AM
|
#20 (permalink)
|
|
Inactive
Join Date: 10-13-03
Location: England
Posts: 2,781
Latest Blog: None
| |