473,406 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Multi-image cycling rollover?

I'm having a bit of trouble with this script. I'm wondering if someone might
help me. What I'm trying to do is to have a multiple image rollover whereby
onmouseover, the image's source will cycle through a few pics and stop. I
got this part to work fine--it's the onmouseout part that I'm having some
difficulties with. I would like everything to be included within one
function, instead of two (one for mouseover and one for mouseout). Here is
what I have:

----------------------------------------------------------------------------
--------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function
KP_multi_img_rollover(subject,navimg1,navimg2,navi mg3,navimg4,navimg5) {
var thesubject = document.getElementById(subject);
var theimgs = new Array(navimg1,navimg2,navimg3,navimg4,navimg5);
var i = 0;
var cycle = setInterval(cycler,300);
thesubject.onmouseout = clearInterval(cycle); setInterval(backcycler,300);
function cycler() {
if (i < theimgs.length-1) {
i = i + 1;
thesubject.src = theimgs[i];
}
else {
clearInterval(cycle);
}
}
function backcycler() {
if (i > 0) {
i = i - 1;
thesubject.src = theimgs[i];
}
else {
clearInterval(backcycler);
}
}

}
</script>
</head>
<body>
<img id="item1" src="TH_basement-entrance.jpg" width="118" height="90"
onMouseOver="KP_multi_img_rollover('item1','navpic 1.jpg','navpic2.jpg','navp
ic3.jpg','navpic4.jpg','navpic5.jpg');">
</body>
</html>
----------------------------------------------------------------------------
--------------------

Now, I realize the problem is with the "thesubject.onmouseout =
clearInterval(cycle); setInterval(backcycler,300);" statement, but I can't
figure out why it isn't working. I thought you could use event handlers as
object properties? Help would be appreciated--thanks.
Jul 20 '05 #1
2 5642
"TheKeith" wrote on 13/11/2003:

<snip>
thesubject.onmouseout = clearInterval(cycle); setInterval(backcycler,300);

When specifying handlers like this, you must use the function name
only. If you include the parentheses, the function is called
immediately. This means that you can't specify parameters. Also, the
setInterval() call above will always be called: the preceeding
semi-colon marks the end of the assignment. You could put all of your
script on the same line and it wouldn't change how it was executed.
The assignment and setInterval() call are two separate statements. To
fix this, define a new nested function:

function myMouseOut()
{
window.clearInterval( cycle );
backcycle = setInterval( backcycler, 300 );
// You need the timer ID to cancel the interval later!
}

and add these to your main function:

var backcycle = null; // With the declarations
....
thesubject.onmouseout = myMouseOut;

<snip>
function backcycler() {
if (i > 0) {
i = i - 1;
thesubject.src = theimgs[i];
}
else {
clearInterval(backcycler);
This is invalid. You can't specify a function for an interval ID
(hence the new variable I introduced above).

<snip>
Now, I realize the problem is with the "thesubject.onmouseout =
clearInterval(cycle); setInterval(backcycler,300);" statement, but I can't figure out why it isn't working. I thought you could use event handlers as object properties? Help would be appreciated--thanks.


Hopefully, that will help somewhat.

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)
Jul 20 '05 #2

"Michael Winter" <M.Winter@[no-spam]blueyonder.co.uk> wrote in message
news:5Z********************@news-text.cableinet.net...
"TheKeith" wrote on 13/11/2003:

<snip>
thesubject.onmouseout = clearInterval(cycle);

setInterval(backcycler,300);

When specifying handlers like this, you must use the function name
only. If you include the parentheses, the function is called
immediately. This means that you can't specify parameters. Also, the
setInterval() call above will always be called: the preceeding
semi-colon marks the end of the assignment. You could put all of your
script on the same line and it wouldn't change how it was executed.
The assignment and setInterval() call are two separate statements. To
fix this, define a new nested function:

function myMouseOut()
{
window.clearInterval( cycle );
backcycle = setInterval( backcycler, 300 );
// You need the timer ID to cancel the interval later!
}

and add these to your main function:

var backcycle = null; // With the declarations
...
thesubject.onmouseout = myMouseOut;

<snip>
function backcycler() {
if (i > 0) {
i = i - 1;
thesubject.src = theimgs[i];
}
else {
clearInterval(backcycler);


This is invalid. You can't specify a function for an interval ID
(hence the new variable I introduced above).

<snip>
Now, I realize the problem is with the "thesubject.onmouseout =
clearInterval(cycle); setInterval(backcycler,300);" statement, but I

can't
figure out why it isn't working. I thought you could use event

handlers as
object properties? Help would be appreciated--thanks.


Hopefully, that will help somewhat.

Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)

I'm an idiot. It works great! Thanks a lot, Mike.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
5
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
0
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
1
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.