Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rollover question

Status
Not open for further replies.

altaratz

ISP
Apr 15, 2001
73
US
I'm using the following image rollover script, but I would like to add 1 small thing.

When the user clicks the link embedded in the rollover, I'd like the image to be permanently the second image (the rollover) - like the VLINK function in the <BODY> tags (there is also an embedded pop-up window function in the link):

Here's the image tag:

<a href=" onclick="image1.src='../../images/news_1_blue.gif';NewWindow(this.href,'name','600','600','yes');return false"><IMG hspace=0 src="../../images/news_1_gray.gif" name=image1 class="domroll ../../images/news_1_blue.gif"></a>

function domRollover() {
if (navigator.userAgent.match(/Opera (\S+)/)) {
var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
}
if (!document.getElementById||operaVersion <7) return;
var imgarr=document.getElementsByTagName('img');
var imgPreload=new Array();
var imgSrc=new Array();
var imgClass=new Array();
for (i=0;i<imgarr.length;i++){
if (imgarr.className.indexOf('domroll')!=-1){
imgSrc=imgarr.getAttribute('src');
imgClass=imgarr.className;
imgPreload=new Image();
if (imgClass.match(/domroll (\S+)/)) {
imgPreload.src = imgClass.match(/domroll (\S+)/)[1]
}
imgarr.setAttribute('xsrc', imgSrc);
imgarr.onmouseover=function(){
this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
}
imgarr.onmouseout=function(){
this.setAttribute('src',this.getAttribute('xsrc'))
}
}
}
}
domRollover();

</script>



Thanks so much for any help!

Ethan Altaratz
 
Don't use the onmouseout call. This will return the image to it's original state. Be aware that this will only work for as long as the user is on THIS page. As soon as the page is refreshed, the original image will return.

There's always a better way. The fun is trying to find it!
 
Actually, onmouseout I want the image to roll back, I just want the image to stay in the rollover position if the link is clicked (and then regardless of whether or not the user mouses over the image any more it would stay on the second image) - any ideas? This is basically to indicate to the user that the link has been clicked.

Thanks,

Ethan Altaratz
 
I tought of this before...

If you got a fixed number of button, you can declare an array of 'switches' to be put to 0 or 1...

Then when you click on the link, you set the switch to 1.

On your onMouseOut='functionName' you just check if the switch is set to 0, if yes, u put back the first image, else, you just do nothing...
 
I'm not exactly getting you - any way you could show a little code?
 
Does the link open a new page?

There's always a better way. The fun is trying to find it!
 
yes:

<a href=" onclick="image1.src='../../images/news_1_blue.gif';NewWindow(this.href,'name','600','600','yes');return false">

it opens a new window 600x600
 
Well, since the focus is lost when the link is clicked and a new window is opened, is it really necessary to keep the onmouseover image? Your users attention will certainly be on the new window and not on the parent page. Could this be an effort in futility? In otherwords, does it really make a difference which image is showing after the link is clicked?

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top