Hello all, I need another set of eyes cause it just isn't working, no matter how identical I make it.
The initRotator function works when called by itself, but when adding another function, only the "other function" works, not the initRotator function. Here's some examples of what I've tried 1st Example using the 2 functions on body tag: -
<head>
-
<script src="css/dw_rotator.js" type="text/javascript"></script>
-
<script type="text/javascript"><!--
-
function initRotator() {
-
// arguments: image name, rotation speed, (optional) path to images
-
var rotator1 = new dw_Rotator('topright_image', 3400, "/images/");
-
// add the images to rotate into that image object
-
rotator1.addImages("main_image7_topright_content.jpg", "main_image2_topright_content.jpg");
-
// rotator1.rotate(); // sometimes may want to call rotate here
-
dw_Rotator.start();
-
}
-
-
// --></script>
-
-
</head>
-
-
<body onload="initRotator();preloadImages()">
-
<img name="topright_image" src="images/main_image7_topright_content.jpg" height="291" width="404" border="0" alt="">
-
2nd Example using a script to call both functions, thus using 1 function in body tag instead: -
<head>
-
<script src="css/dw_rotator.js" type="text/javascript"></script>
-
<script type="text/javascript"><!--
-
function initRotator() {
-
// arguments: image name, rotation speed, (optional) path to images
-
var rotator1 = new dw_Rotator('topright_image', 3400, "/images/");
-
// add the images to rotate into that image object
-
rotator1.addImages("main_image7_topright_content.jpg", "main_image2_topright_content.jpg");
-
// rotator1.rotate(); // sometimes may want to call rotate here
-
dw_Rotator.start();
-
}
-
-
// --></script>
-
-
<script type="text/javascript">
-
function loadtwo() {
-
initRotator();
-
preloadImages();
-
}
-
</script>
-
-
</head>
-
-
<body onload="loadtwo()">
-
<img name="topright_image" src="images/main_image7_topright_content.jpg" height="291" width="404" border="0" alt="">
-
The img name="topright_image" has been tried with out the underscore seperation. I've also tried the onload function without the ending semi-colon on the end: - <body onload="initRotator();preloadImages();">
-
<body onload="initRotator();preloadImages()">
-
<body onload="preloadImages();initRotator();">
-
<body onload="preloadImages();initRotator()">
The javascript: dw_rotator.js, Works fine, unless I'm not seeing something. -
dw_Rotator.restartDelay = 3400; // delay onmouseout before call to rotate
-
dw_Rotator.col = [];
-
-
// arguments: image name, rotation speed, path to images (optional),
-
// target, i.e. name of window to direct url's to onclick (optional)
-
function dw_Rotator(name, speed, path, tgt) {
-
this.name = name; this.speed = speed || 3400; // default speed of rotation
-
this.path = path || ""; this.tgt = tgt;
-
this.ctr = 0; this.timer = 0; this.imgs = []; this.actions = [];
-
this.index = dw_Rotator.col.length; dw_Rotator.col[this.index] = this;
-
this.animString = "dw_Rotator.col[" + this.index + "]";
-
}
-
-
dw_Rotator.prototype.addImages = function() { // preloads images
-
var img;
-
for (var i=0; arguments[i]; i++) {
-
img = new Image();
-
img.src = this.path + arguments[i];
-
this.imgs[this.imgs.length] = img;
-
}
-
}
-
-
dw_Rotator.prototype.addActions = function() {
-
var len = arguments.length; // in case an argument's value is null
-
for (var i=0; i < len; i++)
-
this.actions[this.actions.length] = arguments[i];
-
}
-
-
dw_Rotator.prototype.rotate = function() {
-
clearTimeout(this.timer); this.timer = null;
-
if (this.ctr < this.imgs.length-1) this.ctr++;
-
else this.ctr = 0;
-
var imgObj = document.images[this.name];
-
if (imgObj) {
-
imgObj.src = this.imgs[this.ctr].src;
-
this.timer = setTimeout( this.animString + ".rotate()", this.speed);
-
}
-
}
-
-
// Start rotation for all instances
-
dw_Rotator.start = function() {
-
var len = dw_Rotator.col.length, obj;
-
for (var i=0; i<len; i++) {
-
obj = dw_Rotator.col[i];
-
if (obj && obj.name ) // check for empty instance created by dw_random.js
-
obj.timer = setTimeout( obj.animString + ".rotate()", obj.speed);
-
}
-
}
-
-
// called onclick of images
-
dw_Rotator.doClick = function(n) {
-
var obj = dw_Rotator.col[n];
-
if ( !document.images || !obj ) return true;
-
if ( obj.actions && obj.actions[obj.ctr] ) {
-
if ( typeof obj.actions[obj.ctr] == "string" ) { // url
-
if ( obj.tgt ) { // open in separate window
-
// add features here if you want, i.e., chrome, size, position, ...
-
var win = window.open(obj.actions[obj.ctr], obj.tgt);
-
if ( win && !win.closed ) win.focus();
-
} else {
-
window.location = obj.actions[obj.ctr];
-
}
-
} else { // function pointer
-
obj.actions[obj.ctr](); // execute function
-
}
-
}
-
return false;
-
}
-
-
// for stopping/starting onmouseover/out
-
dw_Rotator.pause = function(n) {
-
dw_Rotator.clearTimers(n);
-
}
-
-
dw_Rotator.clearTimers = function(n) {
-
var obj = dw_Rotator.col[n];
-
if ( obj ) {
-
clearTimeout( obj.timer ); obj.timer = null;
-
}
-
}
-
-
dw_Rotator.resume = function(n) {
-
dw_Rotator.clearTimers(n);
-
var obj = dw_Rotator.col[n];
-
if ( obj ) {
-
obj.timer = setTimeout( obj.animString + ".rotate()", dw_Rotator.restartDelay );
-
}
-
}
-
2 6129
I didn't understand the problem clearly, but I you may work like this...
Declare a universal variable as a flag (var flag=0;).
At the end of a preloadImages function, turn the flag on (flag = 1;).
Using setTimeout, keep on looping untill the flag is on... Once it is on, run the initRotator function.
eg... - function waitToInitRotator() {
-
if (!flag) var wait = setTimeout("waitToInitRotator()", 100);
-
else initRotator();
-
}
Just give it a try... or the other way round (use flag in initRotator and creeate a function waitToPreloadImages())
I got it figured out, What I needed and was having problems with was calling on more than 1 function on the body tag when page loaded. The problem was in a scroller script on same page that I forgot about and it had a window.onload=populate that was causing the override. So after remove that from the scroller script and implementing the following code, I was able to get all three items to load upon page load. - <script type="text/javascript">
-
function loadthree() {
-
initRotator();
-
preloadImages();
-
populate();
-
}
-
</script>
-
</head>
-
<body onload="loadthree();">
Sign in to post your reply or Sign up for a free account.
Similar topics
by: alanstew |
last post by:
With the body tag calling out 'window onload', a function with a
'window.open' fails at the 'window.open' line. If I cut out the body
tag, the function executes as normal.
At first I thought it...
|
by: ryan.mclean |
last post by:
Hello everyone. Hope ya'll had a nice New Year. Anyway, my question
is why won't this work? I must be doing something dumb . . . here is
the code:
in the body tag, I have this code (just to...
|
by: crwng |
last post by:
Hi. I'm trying to forward my web site users to a more friendly error
message whenever they encounter a 404 page not found error.
So far, it's been working fine...until XP SP2 came onto the...
|
by: Viken Karaguesian |
last post by:
Hello all,
I have a question. I trying to run two Javascripts on my webpage, both
of which need a <body onload> command. They are as follows:
<body onload="runMe()">
<body...
|
by: laredotornado |
last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to
have my Javascript function execute from the BODY's "onload" method,
but if there is already an onload method defined, I would...
|
by: Patient Guy |
last post by:
I have this in a document:
<body onload="a_function(this);">
In an (external) script file, I define a_function() as follows:
function a_function(obj)
{
// surprise errant coding here
|
by: Earl Teigrob |
last post by:
I am trying to build a custom control to wrap my smart navigation
implimention (not microsofts 'cause it has problems)
The follow code works fine when the onclick and onload events are defined in...
|
by: lwhitb1 |
last post by:
I have been trying to load a javascript function from the body onload
html tag, but I only want the function to load the first time the page
is loaded: I have investigated but haven't found...
|
by: Jason |
last post by:
Hi,
Here's the scenario:
I have a web application that has window A and window B.
A user has both window A and B open - window A is in the foreground and
window B is behind it.
If the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
| |