I've been trying a number of different approaches but can't seem to get it right. The idea was to loop the main funtion of the script (loadContent) by ending with the setTimeout, that I had to move to another function. Why, I don't know, but that's the only way it works. I'm a professional PHP programmer, getting to grips with Javascript in this era where Ajax rules firmly is part of my job. Can't say I have been enjoying the experience so far, though.Right, enough bashing for today! The idea was to have a simple script, linked to a php script that would load images, based on the data sent via Javascript and an XML datafile. This does happen, only: the timeout of 5 or 6 seconds doesn't seem to last even a millisecond.
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:
I have a script that I have tried running using both setTimeout and setInterval. It works fine in every browser except safari 3. It will run fine for a few loops and then stop.
I wanna get some deep information about how browser implements the dispatch mechanism of events , native setTimeout and setInterval. Any books or articles reference it?
After upgrading from 1.5.1 to 1.6.1 the auto-play feature of this slider speeds up. I'm using this code: [URL]. 4000 milliseconds is specified in the script if you view source, however, if you let the slider run for a few minutes(I haven't determined a consistent time frame for this) then the slider begins to change one after the next almost immediately without waiting 4 seconds. .attr() is used once in the script, but after reading the core teams suggestions regarding .attr() after upgrading to 1.6.1 it doesn't seem like I'm supposed to change anything.
Same problem with this slider which is from [URL] simple-jquery-image-slide-show-with-semi-transparent-caption: <script type="text/javascript"> $(document).ready(function() { //Execute the slideShow slideShow(); });
function slideShow() { //Set the opacity of all images to 0 $('#gallery a').css({opacity: 0.0}); //Get the first image and display it (set it to full opacity) $('#gallery a:first').css({opacity: 1.0}); //Set the caption background to semi-transparent $('#gallery .caption').css({opacity: 0.7}); //Resize the width of the caption according to the image width $('#gallery .caption').css({width: $('#gallery a').find('img').css('width')}); //Get the caption of the first image from REL attribute and display it $('#gallery .content').html($('#gallery a:first').find('img').attr('rel')) .animate({opacity: 0.7}, 400); //Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds setInterval('gallery()',6000); } function gallery() { //if no IMGs have the show class, grab the first image var current = ($('#gallery a.show')? $('#gallery a.show') : $('#gallery a:first')); //Get next image, if it reached the end of the slideshow, rotate it back to the first image var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first')); //Get next image caption var caption = next.find('img').attr('rel'); //Set the fade in effect for the next image, show class has higher z-index next.css({opacity: 0.0}) .addClass('show') .animate({opacity: 1.0}, 1000); //Hide the current image current.animate({opacity: 0.0}, 1000) .removeClass('show'); //Set the opacity to 0 and height to 1px $('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 }); //Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect $('#gallery .caption').animate({opacity: 0.7},0 ).animate({height: '100px'},500 ); //Display the content $('#gallery .content').html(caption);} </script>
one could add a 'start' & 'stop' (id="stopit") button to control the simple sprite animation. My Javascript looks like this (note that it works in tandem with the core.js that comes with the book; see the ZIP file i've attached):
Code: var Robot = { init: function() // initiate via core.js {
[Code]....
clicking on the 'start' button more than once speeds up the animation, more with each successive click. Clicking the 'stop' button will only finally stop the animation if it's done the same number of times as the 'start' button was clicked.
I want to make a page which loads the div's with ajax The html code of the page is
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> //styles and other script code <script language="javascript" src="../js/intro.js"></script> </script> [Code]....
Now the problem is that javascript "freezes" and setInterval does not work.. Is there any solution to load the files order such i have it in code one-by-one and run the message function?
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.
when I call obj.loop(); 'this' in obj.next refers to setInterval and not obj . I realise I can add var ref = this; and send it with setInterval but is there something I can do to get 'this' to refer to obj when in obj.next?
I'm attempting to create a small function that when called upon will change the CSS background property 10 times at 80 millisecond intervals. I'm pretty sure setInterval() is the way to go about this, but I've been toying with my script for an hour and can't get anything to work.
At each 80 millisecond interval, the CSS background property should change like so:
I would normally just use the background-position property, but it seems the hyphen throws javascript for a slip. It's really not necessary for this function, but if there's a way to use hyphens, it would be good to know for future reference.
So this works ok in the sense that the animation is performed smoothly. But to my understanding it should expand the height of the box 1pixel every 1ms, so it should expand very quickly from the base height to the maxHeight limit, but I click on the link and it animates soooooo slooooowly -- smoothly, i mean, but it takes well over a minute to expand to the full height. I just need to speed the damn thing up! Also, if i change "box.heightCount++;" to "box.heightCount+=1;" it gets all messed up. What am I missing here?
i'm scratching my head over achieving similar results with setInterval() function, and how I can keep it from looping infinitely.
I want to do something like this: var i = 0; var endTime = now + ((1000*60)*2); // 2 minutes after now while (now <=endTime) { i = i + 1; now = new Date().getTime(); } document.write("total iterations: " + i);
however you can't do this because of lag issues, so i'll settle for using setinterval on its smallest interval of a millisecond, here is my attempt to translate the above to a setinterval solution: var endTime = now + ((1000*60)*2); // 2 minutes after now var intervalID = setInterval(loopFunc(endTime),1); function loopFunc(endTime,intervalID) { if (new Date().getTime() <= endTime) { i = i + 1; } else { clearInterval(intervalID); }}
as you can see I have prolbems figuring out how to stop the interval from continuing to iterate, and passing the interval id, I'm clueless Also I'm clueless on echoing the total iterations via this method.
is not working correct. doSomething is not known. i think, setInterval is not inside the class, so doSomething is private and unknown for the interval.
I've developed a plugin for a simple slide show. and here is the code [URL] The problem is when I mouse over the pic, the console error logs: "slideSwitch is not defined" The same error would still happen if I define function slideSwitch(){} and call
Inside of $(document).ready(function () I have: var refre****= setInterval(function(){ $('#mydiv').load("mypage.htm"); }, 9000); This is working great in IE, it loads mypage.htm into mydiv every 9 seconds. If I change the contents of mypage.htm I can see it in mydiv after 9 seconds with IE, but not with Firefox. With Firefox I can see the reloading symbol on top of the tab every 9 seconds, but I don't see the page changed.
I am new in web development. I think this problem is related to javascript, I have write script which will change images after 2sec, through setInterval function. Script is as follows.
<script> var images = new Array ("img/1.jpg", "img/2.jpg", "img/3.jpg"); var currentIndex = 0; function Start(){ setInterval("ChangeImage()", 2000); }function ChangeImage(){ currentIndex++; if(currentIndex == images.length){ currentIndex = 0; } document.images[0].src = images[currentIndex]; } </script>
But when I place in img tag which is in third row div and reload page, these series of images show in first row div. It does not show where I have specified area for it in css.
First row div: <div id="menu"> <img src="header/menu.png" name="menuImg"/> </div> My series of images show in this div when I load page.
I just encountered a rather strange issue with setInterval() in Firefox. Take for example this code:
function test(){ setInterval("window.status+='x'", 1000) }
test() test()
So I call test() twice, which should mean the status bar gets appended 2x's every second. This is the case in IE6 and Opera, but in Firefox, it pauses every 2 seconds, and adds 4x's each time. Basically, Firefox seem to not update every second but every 2 seconds as a result. Anyone know what's going on?
function load(cv) { setInterval("checknew('cv')",1000); } checknew sends the number 1 or 0 depending on what load sends, and in turn, its just alternating 1/0 every second.
I am unsure how to send the number I get in load(cv) to checknew(cv) every 1 second on setInterval.
I am trying to use the variable "theObject" to pass a value to setInterval. But I keep getting the error that "theObject" is not defined. But I have tested it with an "alert" just before the "if" statement and I know that not only is it defined, but it has the correct value.
Why won't setInterval recognise the variable? Is there a way to get this to work?
I tried putting the method in setInterval in quotations, which runs continuously but it won't allow me to pass parameters so in turn it does nothing. The way I have it now passes parameters but doesn't run continuously.
$('#icon' + i).bind('click', function() { var icon = this.id; var iconID = setInterval(iconExpand(icon),5); }); function iconExpand(obj) { var mLeft = $('#' + obj).css('margin-left'); var mTop = $('#' + obj).css('margin-top'); [Code]....
I'm calling `setInterval(myfunc, 100);`. That function receives one parameter which seems to be -3, 0, 3, 6 or 9. This isn't a problem, but I'm wondering what it is. Does someone know?
Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1