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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I trigger a rollover without rolling over?

Status
Not open for further replies.

leadman

Programmer
Jun 11, 2001
177
0
0
US
Hi all,

I was wondering, is there a way to have the rollovers on my page show the 'over' image using a timer? Im trying to get the buttons to all flash once, in succession, when a user enters the page.
 
go to click on scripts and look into chapter 3 - specifically creating cycling banners. thsi will show you how tro use a timer for changing images. --------------------------------------------------
Goals are dreams with deadlines
 
U could do this using document.images["imageName"].src = 'something.jpg' and setTimeout("javascript", delai)

I'd be interested in seeing this kind of effect. let me know if you finish this anytime soon.
Gary " Haran
 
ok ok I was too impatient so I decided to do it myself. You can base yourself on the way this works.

<html>
<head>
<script>
var delai = 50; // milliseconds between each change.
var currImg = 0; // tells us wich image we are on

function imageEffect()
{
if (currImg > 0)
{
// set last image back to original src.
document.images[currImg-1].src = &quot;purple.png&quot;
}

if (currImg < document.images.length)// stops us from going on forever
{
// sets image to new src
document.images[currImg].src = &quot;teal.png&quot;

// tells us to do the same but with the next one in line
currImg++

// repeat this function for the next image
setTimeout(&quot;imageEffect()&quot;, delai)
}
}

</script>
</head>

<body onload=&quot;imageEffect()&quot;>

<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>
<img src=purple.png height=10 width=10>

</body>

</html>

Gary &quot; Haran
 
now for the same stuff except more easily scalable and with no respect for older browser :


<html>
<head>
<script>
var delai = 50; // milliseconds between each change.
var currImg = 0; // tells us wich image we are on

function imageEffect()
{
if (currImg > 0)
{
// set last image back to original src.
var img = document.images[currImg-1]
var other = img.getAttribute(&quot;otherSrc&quot;)
img.setAttribute(&quot;otherSrc&quot;, img.src)
img.src = other
}

if (currImg < document.images.length)// stops us from going on forever
{
// sets image to new src
var img = document.images[currImg]
var other = img.getAttribute(&quot;otherSrc&quot;)
img.setAttribute(&quot;otherSrc&quot;, img.src)
img.src = other

// tells us to do the same but with the next one in line
currImg++

// repeat this function for the next image
setTimeout(&quot;imageEffect()&quot;, delai)
}
}

</script>
</head>

<body onload=&quot;imageEffect()&quot;>

<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>
<img src=purple.png otherSrc=teal.png height=10 width=10>

</body>

</html>


Gary &quot; Haran
 
notice the otherSrc attribute is used. That means that you could have anything you want in the src and otherSrc attribute.

You could for example add another image with anything you want for src and otherSrc.

<img src=myImageOn.png otherSrc=myImageOff.png>

would work easily without modifying the second script.
Gary &quot; Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top