Simple N00b SetTimeout Or Onload Problem
Mar 28, 2006
What I want is an element with a shifting background image:
<html><head>
<script type="text/javascript">
var x = 0
var y = 0
inc = 4
function bgWander(el){
x = x + Math.round(2*inc*Math.random())-inc
y = y + Math.round(2*inc*Math.random())-inc
el.style.backgroundPosition = x + 'px ' + y + 'px'
setTimeout('bgWander(el)',200)
}
</script></head><body>
<a onLoad="bgWander(this)" href=""
style="background:url(images/bgbar.png)">Link</a>
</body></html>
Can you show me the error of my ways?
View 3 Replies
ADVERTISEMENT
Dec 24, 2009
I'm trying to graph line with a delay between each line drawn - my code is:
var jg = new jsGraphics('Canvas');
jg.setColor('maroon');
jg.drawLine(40,130,80,120);
setTimeout('jg.paint()',10000);
jg.drawLine(80,120,120,110);
setTimeout('jg.paint()',10000);
Unfortunately it draws all the lines at the same time i.e the setTimeout function doesn't like the paint method.
View 1 Replies
View Related
Dec 15, 2010
I'm new to JavaScript, and have been playing around with a few simple functions to get going. However, I've hit a problem that I just can't fix, I'm trying to write a simple function to animate the collapse of a div using setTimeout (I know, jQuery does it a lot better), and it's gotten the best of me. The only error it's giving me now is
Code: missing ; before statement on line 25 but I can't see why. I assume it's something to do with my abuse of the setTimeout syntax (why does it insist that everthing is enclosed in quotes.I'm sure there are much better scripts than mine, and searching the forum I've come across Vic Phillips' fine specimen which mostly went over my head. But if I just wanted it to work I'd use jQuery - I'm more interested in why it's not working.
code is below. In addition to this I've also got an external script to compensate for browsers without getElementsByClass, but it should work in modern browsers up to the point where it doesn't!
[Code]...
View 4 Replies
View Related
Oct 25, 2011
I've noticed that setTimeout seems to return a simple integer as it's "id" which can be used to clear the timeout ahead of time. So, in order to have multiple setTimeouts called (which requires the previous one to be cleared before the next one is called), I simply did this:
clearTimeout(setTimeout(function() {
/* some code */
}, 1000) -1);
Note the "-1"... each time this code is called, it starts a new setTimeout and clears "instance-1" which is supposed to be the previous instance. The idea is that this block can be called hundreds of times, and when the calling finally stops, the inner code is executed 1 second later. This SEEMS to be working (yes, even in MSIE!). Question is, am I fooling myself? Is this wrong?
View 4 Replies
View Related
Feb 7, 2006
it sound's crzy but it happened to me the other time:
I have something like this:
document.write('<br>SOMETHING ' + nFrames + ' SOMETHING')
and when I tregger it, it delet's me everyting in the web and then put's this ^, my question:
Is there any chanse that I used another method or I put something dso it is not deleted
View 8 Replies
View Related
Aug 20, 2011
I'm super new to any kind of java script. What I want is a menu that, when clicked, changes the background color of a table cell to blue. When a different option is clicked, the current highlighted table should turn back to gray and the new selection should be blue. Well, I have all of that working. What I need now is just to have the first option start out highlighted and to become unhighlighted when another option is clicked.
[Code]...
View 9 Replies
View Related
Jul 12, 2010
I have the following function that's supposed to say "Please make a guess" 20 seconds after an initial confirmation is displayed. However, it's immediately displayed as soon as someone hits "Cancel". If I change it's time to 40000 (20 seconds after the initial function is called), it does do it 40 seconds total, so it kind of does what I want. So it seems that the second setTimeout is initiated from the time the script is called generally, but I'm looking for a way specifically to have the 20 seconds start only after the "cancel" button is hit.
[code]...
View 1 Replies
View Related
Jul 23, 2005
I'm having a hard time figuring out why the onload event is not being
called for the frameset window in the following simple example. It is
being called for each of the component frames. Code:
View 5 Replies
View Related
Dec 3, 2005
I wander what gets loaded the fastest (1-2 or 3) in what succession:
<head>
<script type="text/javascript">
function andAction() {
// doing stuff
}
</script>
</head>
<body onload="andAction();">
<script type="text/javascript">andAction()</script></body>
just in the head and nothing more
This I am sure off:
<head>
<script type="text/javascript">
window.onload = function andAction() {
// doing stuff
}
</script>
</head>
<script type="text/javascript">andAction()</script></body>
just in the head and nothing more (should be 1)
Third and last which is faster:
body onload or window.onload
View 3 Replies
View Related
Jul 23, 2005
I'm seeing a difference in behaviour between
window.onload = f();
and
<body onload="f();">
Specifically, window.onload appears to fire before all the elements of
the page have been rendered. As the difference is consistent across
IE/Moz/Opera, I'm assuming it's deliberate - can anyone point me
towards where this behaviour of window.onload is defined in the
documentation? TIA. Code:
View 2 Replies
View Related
Jul 23, 2005
I'm wondering if its because I don't fully understand setTimeout(). I have a web page that calls a function on the Onload. This function calls two separate functions and then
uses setTimeout() to keep calling itself. Each function randomly generates
a number and then I update the image.src with that.
If I run setTimeout() on just one function by itself, it almost always displays a new pic...but when I put the setTimeout() in the startup function a get a lot of duplicates. I've been watching it for a long time and I don't think it's a coincidence. Any idea
as to why it seems like both functions don't run/update the pic all the time? If I uncomment the line, alert("hello"), it runs all the time? Code:
View 3 Replies
View Related
Jul 1, 2006
i'm working on a small idea and i would like to run this code:-
document.getElementById(id).style.height = origheight+"px";
after a set time period (about 20ms i guess ;) ), however, the following line creates errors:-
var t1 = setTimeout("document.getElementById('+id+').style.height = '+origheight+'px' ",0.5);
any ideas why?
View 6 Replies
View Related
Jul 23, 2005
<img src=http://xxx.com/yyy.jpg
onmouseover="settimeout("document.location='http://www.google.com'"),
2000">
I want to have a 2 seconds delay before it is directed to an URL when the
mouse is over the image.
However, it seems that setTimtOut does not like parameters in the function
part.
View 5 Replies
View Related
Feb 21, 2006
I have a HTML page with a form with 2 buttons like this
....
<input type="button" value="Add" onClick="ClickAdd();"/>
<input type="button" value="Reset" onClick="ClickReset();"/>
....
I also have this javascript code:
----------------------------------------
function ClickAdd() {
setTimeout(test.Add, 100);
//test.Add();
};
function ClickReset() {
setTimeout(test.Add, 100);
//test.Reset();
};
Test = function () {
this.total = 0;
};
Test.prototype.Add = function() {
this.total++;
alert(this);
};
Test.prototype.Reset = function(i) {
this.total = 0;
alert(this);
};
Test.prototype.toString = function() {
return (this.total);
};
test = new Test();
-------------------------------------------
the thing is:
in the ClickAdd function, if i call test.Add() directly, is works ok But if I call it using setTimeout, the /alert(this)/ shows [object Window]....
View 4 Replies
View Related
Mar 11, 2006
Does anyone know whether the ECMA, or an other standard document,
specifies a maximum for the value that can be pass to the setTimeOut()
function in Javascript?
View 28 Replies
View Related
Aug 14, 2006
The below pasted code is my attempt to get the text of a span to change
every second. However, it seems to just set the text of the span to be the last item
in the array. Code:
View 3 Replies
View Related
Apr 3, 2007
I am modifying the suckerfish dropdown code to use settimeout to have
a slight pause before the menus disappear to make it more user
friendly. I have hit a snag with the following statement:
li.
{
timerID=setTimeout('this.getElementsByTagName("UL")
[0].style.display = "none"', timecount);
}
If I put take the statement
this.getElementsByTagName("UL")[0].style.display = "none";
out of the settimeout function, it works. (w/o the pause, obviously).
With the settimeout function, I get "this.getElementByTagName is not a
function" error.
I have tried putting this.getElementsByTagName("UL")[0] is a variable
and then using that in the settimeout function, but then each li will
only open the very last menu in the list. (ie all the menu items open
the last sub menu) Code:
View 4 Replies
View Related
Apr 3, 2007
Can I have two setTimeouts running at the same time - with two
different intervals?
I want to start one timer and, before it times out, start another one
I've tried this and they seems to interfer with one another.
View 7 Replies
View Related
Oct 25, 2007
var SessionTimer;
function StartSessionTimer()
{
SessionTimer = setTimeout('RedirectToSessionTimedOutPage(),60000)
}
function RestartSessionTimer()
{
clearTimeout(SessionTimer);
StartSessionTimer();
}
function RedirectToSessionTimedOutPage()
{
window.location = '/SessionTimedOut.html'
}
When I load the page and call StartSessionTimer(), I know it works because the page redirects after ten minutes (the value of 60000). However, in certain situations I need to be able to call back to the server with AJAX and then have the timer reset - that's when I call the RestartSessionTimer() function. When I do this, for some reason the ten minute window does not get reset.
To troubleshoot, if I remove the second line in the RestartSessionTimer() function the redirect is getting blocked (as planned). However, when I put the second line back in, the page just redirects as originally called - the SessionTimeout value is never
reset properly.
The code above looks good to me, but for some reason the SessionTimeout var does not get reset in the RestartSessionTimer function; it retains its original value?
View 2 Replies
View Related
Jul 20, 2005
I have a pop-up menu; one of those where you scroll over the menu, and
a submenu pops up beneath it. Everything's running smoothly on every
browser I've tested with, except for one problem on every browser: the
"clearing" of the menu.
The menu itself is being called by:
onMouseOver="menu(1)" onMouseOut="clearIt()"
function menu(x) let's "x" refer to a predefined array, which
determines which menu to pop up. That menu is stored in a variable,
showMenu. If x==0, then it changes showMenu to a whitespace, thus
"clearing" the submenu altogether.
clearIt() is a simple function, pasted here:
function clearIt() { setTimeout("menu(Ɔ')", 7000) }
The idea is that the menu will disappear after 7 seconds. The problem
I'm having, though, is that the 7 seconds starts after the first
onMouseOut, and doesn't restart when the visitor mouses over the
second button. So, if I look at the first submenu for 6 seconds, then
when I go to the second button the menu only stays open for 1 second,
instead of starting the timer over.
View 1 Replies
View Related
Mar 19, 2009
Here we are again pondering why setTimeout will not work, or rather mucks things up. This will work. addOn(obj);
function addOn (obj)
{
var parentNode = obj.parentNode;
var span = parentNode.getElementsByTagName("span")[0];
span.style.display="block";
thkOn(obj);
[Code]...
View 4 Replies
View Related
Nov 7, 2011
function funt()
{
var link = document.getElementsByClassName("class")[0];
[code]....
View 5 Replies
View Related
Jan 10, 2010
I have a window up whose Javascript implementation checks for a cookie with code something like this:
function lookieCookie()
{
alert(document.cookie);
setTimeout(lookieCookie, 10000);
}
The first call to lookieCookie is in the onload event handler. The cookie is actually set by a PHP routine that is in another script. The PHP script certainly appears to be setting the cookie. The alerts from lookieCookie are clearely happening at the appropriate time intervals (I can't get into the room with the actual code at the moment, so if I have messed up the syntax here, I know that it is not messed up in the real code), but the cookie being set from PHP does not show up.
Obviously the PHP might be doing the wrong thing. In tha case I have to get on the guy that writes the PHP script. Should the code I wrote work even if the cookie is set after the page has loaded, but between iterations of lookieCookie()? If yes, then I must get on the PHP coder and get his page fixed.
View 1 Replies
View Related
May 17, 2011
I have an image that when hovered, another image pops up (this popup image has a 'learn more' button on it), but when someone attempts to mouse over the button, the image restores to its original image. I was advised to use 'setTimeout' but do not know how to apply it with the following code...
I understand WHY it's going back to its original state (the mouse is hovering outside of the area coordinates), but how can I apply the setTimeout script to DELAY the image from going back to its original state?
View 3 Replies
View Related
Nov 6, 2004
Script is suppose to print out a string with a short delay between chars... like a typewriter... Why doesn't this work?
<script type="text/javascript">function hehe(bam) { document.write(bam)}function CharPrinter(st) { num = st.length; i = 0; while(i <= num) { bam = st.substr(i,1) setTimeout(hehe(bam),1000) i++; }}CharPrinter("lol");</script>
View 10 Replies
View Related
Sep 3, 2005
I'm trying to build the framework for an AJAX back/forward button fixer. Basically it uses the hash fix for them (using text after the # to add history objects). To this effect, the function to check for updates has to be run every second or so. No problem, I'll just use setInterval for that.
For whatever reason, though, setInterval gives me an error. Specifically that oldLocation (global variable) is undefined (in the checkURL function). So I try setTimeout. Same thing. When I just call the function explicitly once (adding checkURL(); to the end of the script) everything works wonderfuly; it's just setting it up on a timer that messes up. Frankly, I've no idea why it's doing this. (The bug just seems so odd) Maybe a more advanced JS coder can shed some light on it.. Code:
View 6 Replies
View Related