JavaScript - Loading Images Into An Array, Then Drawing To Canvas
Code:
<html> <head> <title>test</title> </head> <body> <script language = "javaScript"> var clouds = []; var i = 0; while(i <= 5) { var cld = new Image(); cld.onload = function() { clouds.push(cld); } cld.src = "cloud.png"; i++; } document.write(clouds.length); </script> </body> </html> Where am I messing up clouds.length returns 0. Why? I know this is simple, but it will get more complex. I can search for the code, but I would like feedback as to what I'm doing wrong. This is more than likely going to be a multi stage question. More to come... ------ Also, I would like to say that this is my first post. Thanks in advance to those who reply. Similar TutorialsHello, Codingforums. I have looked on Google for a solution, done a handful of things, and cannot get my script to draw to the page. Code: <html> <head> <script type="text/javascript" src="imageFuncs.js"></script> <script type="text/javascript"> showImages = function() { var drawingCanvas = document.getElementById("map"); // Check the element is in the DOM and the browser supports canvas if (drawingCanvas.getContext) { var ctx = drawingCanvas.getContext("2d"); var imageSources = new Array("map.jpg"); var images = new Array(); images = loadImages(imageSources); for (var i = 0; i < images.length; i++) { var img = new Image(); img.src = images[i].src; img.onload = function(){ ctx.drawImage(img,0,0,screen.width,screen.height); } } } } </script> </head> <body onload="showImages()"> <canvas id="map">Your browser does not support canvases...</canvas> </body> </html> The problem appears on the ctx.drawImage(img,0,0,screen.width,screen.height); line. I read that the drawImage method will not draw the image if the images are not loaded, which is why I tried an onload event for img. When I run the code the way it is now, I get a attempt to run compile-and-go script on a cleared scope error from Firebug. When I remove the onload event, the script runs without errors. Either way, no image is drawn on the page. Any help? If it helps, this is the loadImages function that I used to get the array of loaded image objects: Code: function loadImages(sources){ var images = new Array(); var loadedImages = 0; var numImages = 0; for (var src in sources) { numImages++; } for (var src in sources) { images[src] = new Image(); images[src].src = sources[src]; } return images; } I have a Canvas controller Class and a new Sprite Controller class Please note I'm not using GIF sprites these are proper programmable sprites like you get in C game engines So i have a Class that controls my Canvas and the Drawing of my Canvas what i mean by this is if you call a new instance of my Class it will create a new Canvas if you already have a canvas you can get a JSRenderEng Object from your Canvas id Now my problem lies with getting my sprites to draw them self's currently my sprites can only appear in one place in a 100x100 px canvas they load as 98x98 1top 1left so they should be a perfect mathematical square inside the canvas with a 1px border, for some reason its not drawing But here is an explination about the classes The Canvas handles the start of the drawing events by going though the sprites attached to the canvas and then calls there draw method, However i seam to have a problem with this my draw method is being fired but is not rendering on the canvas can any one spot the problem. PHP Code: this.draw = function(){ //this.updateParams(); var context = this._canvas.getContext("2d"); context.beginPath(); context.fillRect( 98, 98, 1, 1 ); context.fillStyle = "#000000"; context.fill(); context.closePath(); } Was putting the width and height and the location in the wrong order (DURRRR) I am trying to create an Asteroids type game using JavaScript along with html5's canvas element for drawing. I have searched around and have looked at examples but I can't figure out what is wrong with my rendering that I do in the game loop that is run every frame. The problem appears to be only that the canvas is not cleared at the beginning of each frame but I feel there might be something wrong also. The code used and shown below only works in Firefox but not Google Chrome or Safari. Here is a picture of what it renders in Chrome: What is is supposed to look like and is in Firefox: Here is my set up for drawing on the canvas: Code: var canvas = null; var c2d = null; //... window.onload = init; function init() { canvas = document.getElementById('canvas'); c2d = canvas.getContext('2d'); setInterval( step, 1000/FPS ); //... //c2d.setTransform(1,0,0,1,0,0); // reset to identity <--Do I need this? } Below is the game loop function. Am I clearing the canvas correctly because it does not clear the screen? Also am I using the save and restore functions correctly? Each asteroid and player drawn is at a different of position and rotation so am I doing it correct to draw them? Code: function step() { //... canvas.width = canvas.width; //clear canvas PROBLEM //Things I have tried: //canvas.height = canvas.height; //clear canvas //c2d.clearRect(0, 0, canvas.width, canvas.height); for (u=0;u<asteroids.length;u++) { c2d.save(); asteroids[u].draw(); c2d.restore(); } c2d.save(); player.draw(); c2d.restore(); c2d.strokeStyle = "#000000"; c2d.stroke(); } Below is the Asteroid and Player drawing functions. The Asteroid is a polygon and the Player is a triangle. Both rotate and are draw correctly but should I be passing a reference to the drawing reference? Code: function Asteroid_draw() { c2d.translate( this.x, this.y ); c2d.rotate(this.angle); for (i=0;i<this.points_x.length-1;i++) { c2d.moveTo(this.points_x[i],this.points_y[i]); c2d.lineTo(this.points_x[i+1],this.points_y[i+1]); } c2d.moveTo(this.points_x[0],this.points_y[0]); c2d.lineTo(this.points_x[this.points_x.length-1],this.points_y[this.points_x.length-1]); } function Player_draw() { c2d.translate( this.x, this.y ); c2d.rotate(this.angle); //Points {0,-12}{7,5}{-7,5} c2d.moveTo(0,-12); c2d.lineTo(7,5); c2d.moveTo(7,5); c2d.lineTo(-7,5); c2d.moveTo(-7,5); c2d.lineTo(0,-12); } Any help is appreciated. I'm having a problem with the <CANVAS> element in JavaScript. here's what i'm trying to do: I need 3 different canvas elements for writing a signature to. they must all 3 be visible at the same time My problem that i'm having is that i can't seem to get the code to work which will write to more than one canvas. here's my code: Code: <html> <head> <script language="javascript"> function WriteSignature(element, event) { document.addEventListener("mousemove", PenHandler, true); document.addEventListener("mouseup", upHandler, true); event.stopPropagation(); event.preventDefault(); function PenHandler(event) { var x = event.clientX; var y = event.clientY; // mouse event goes here var canvas1 = document.getElementById("Canvas1"); var ctx = canvas1.getContext("2d"); var PenSize = 2; ctx.fillStyle = "Black"; ctx.fillRect (x, y, PenSize, PenSize); event.stopPropagation(); } function upHandler(event) { document.removeEventListener("mouseup", upHandler, true); document.removeEventListener("mousemove", PenHandler, true); event.stopPropagation(); } } </script> </head> <body> <Canvas id="Canvas1" Width="400" Height="100" Style="border:2px solid black" onmousedown="WriteSignature(this, event);"></Canvas><br><br> <Canvas id="Canvas2" Width="400" Height="100" Style="border:2px solid black" onmousedown="WriteSignature(this, event);"></Canvas><br> </body> </html> So I'm creating a game and decided to use a canvas for the map. The map is a big pictures 500kb+ (6400x6400px) and the canvas size is 320x320 so I am displaying only part of the image at a time and have the page reload on button click for database purposes. What I'd like help with is performance. Currently it's taking a few secs to reload every time and it seems that it causes some cpu strain (can't switch tabs while loading). Could I stop the canvas from reloading the image each time the page is reloaded and if so then how? Can I make the canvas only load a part of the image, if so then how? If neither is possible any tips, solutions how to solve the performance issues? hiya, I just have a specific question regarding to use a canvas-element with javascript I have one empty canvas that I want to add 9x7 smaller image elements to, the function "regRead" gets an image-element-code from a global register and that element code is then changed to a base64-encoded string for use as src for the currect image. the problem is that when i run the script, all the 63 images added to the canvas gets the same content even if imgCode show different values in debug, i appreciate some solution feedback. Code: function UpdateCanvas (CanvId) { var canvIDNames = ["front", "back"]; // DOM IDs var currentCanvas = document.getElementById(canvIDNames[CanvId]).getContext("2d"); var newImg = ""; var topLeft = CanvId * 63; var bottomRight = topLeft + 63; var xa = 0; var posX = 0; var posY = 0; var imgCode = ""; for (xa = topLeft; xa < bottomRight; xa++) { newImg = new Image(); imgCode = regRead(xa, 1); newImg.src = getBase64src(imgCode); newImg.onload = function () { currentCanvas.drawImage(newImg, posX, posY); if (posX == 400) { posX = 0; posY += 90; } else { posX += 50; } } } } is there a way to after thye page load add an image. So maby loading it in the background and just showing it when you click a button?
Hi I am currently doing a photography site. I would like to do a 'portfolio' page, but would like to pre-load the images so that they appear on-screen faster. Do I need to connect code to <body onload>? I have some rollover images on my website, and they don't switch until the page is finished loading. Is this standard? Is there a way to have the rollovers work when the page is still in the process of loading all the images? Thanks Hi Currently my website waits till all images are loaded up first: Code: $(document).ready(function(){ * LOAD UP ALL THEM IMAGES FIRST... * $(window).load(function() { letsLoad(); fadingEffects(); }); However my website now has over 200 images on the website and now its taking way too long to load the images. My question's a 1. Is it possible to either load the site when its around 20% or even 50% loaded? OR 2. If its possible to give certain images a tag?? and when these images are loaded then the site loads? Heres a link to the site - must warn you need broadband and a high speed connection takes way to long to load. Takes me around 1minute 30seconds http://www.arcvizio.co.uk/ovoma/2/index.html Thanks Hello. I've recently implemented this really cool jQuery preloader called queryLoader. When a visitor comes to my site they are fed all the important images for the entire site (it's a very small site). During that time queryLoader shows a percentage loading animation, and once all the images are loaded it wipes the screen & displays the website. I've placed another custom animation in the "page loading" div, and i want to make sure it loads first so that it is displayed while the rest of the images get downloaded. I've tried pre-loading with javascript as the very first script in my header, before jQuery or queryLoader get loaded, like this: Code: <script type="text/javascript"> pic1= new Image(250,300); pic1.src="images/page_loading.gif"; </script> <script type="text/javascript" src="scripts/jQuery.js"></script> <script type="text/javascript" src="scripts/queryLoader.js"></script> However, this doesn't seem to be that effective. When i clear browser cache and reload the page, the page_loading.gif sometimes doesn't appear until the site is almost completely loaded. Is there a more effective way to assure the page_loading.gif gets loaded before any other images? My site is jugtones.com if that helps in any way. Thanks for your time, -Scott Greetings, I am looking for either a JavaScript or Coldfusion solution to the following problem. First, there are over 60 million product photos so downloading and resizing the photos using Coldfusion would be very tedious. I would like the display an image within a 100 x 100 pixel container. If the height or width of the image is great than 100 pixels, the image should reduce in size to fit within the 100 x 100 pixel container. I want to avoid pixelation of the images as much as possible. All images are external and not on the local server so I only have an image URL. I would like to hide all images until they are resized appropriately. Does anybody know of a piece of javascript code that can do something similar to this? Sincerely, Travis Walters Hello, I have develop a piece of code that when the user loads the html page it will load a local image but if the image doesn't exist it will load from a remote server. The question that remains is if it's possible to make an event in case the image is load locally? 1) HTML Page is load 2) If image doesn't exist locally reload from the server 3) If the image is load locally report back to the site Is the 3) possible? Hey, guys, my first post here on the forums, I hope this is the right place. This technically uses Javascript + PHP + XML, but the problem is more based on Javascript than the other two. That, and there are 380 people viewing Javascript and 8 people viewing XML, I decided to take the path of lesser resistance. Also, the code I used, I'm sure there are a million shortcuts that could be used. So if you can give me suggestions, I would Love to hear them because I'm still learning Javascript + PHP + XML and would be very grateful to learn how I could be more efficient What I'm creating is a Form that takes variables from an XML for users to fill out. Users can choose between products, and then when the product is clicked, it loads the options from an Array within the XML so... The question is Products Load from an Array Options Load from the chosen Products? I'm thinking this can be done two ways. Maybe a separate XML can be used for Options but then how would I link each one for each product? Or, can I load the Options in the same XML for each Product and load an array for each Product's Options? --- Later on, I need to figure out how to create a new element for each form the User fills out. IE They finish filling out the options and volume for 20 GI JOES. So it should save those Variables and the User Filled Variables. And then allow you to fill out a new product. Appending to the last form filled out IE 20 GI JOES [Color Red] [Eating Pizza] [Wearing Cowsuits] 12 BARBIES [Color Blue] [Eating Sushi] [Wearing Bearsuits] But I'll do my own reearch for that before I start asking here on how to do that --- This is my Code so far, some of you will recognize it from W3 Schools --- Code: JS oldTextAry = new Array(); var xmlDoc; if (window.XMLHttpRequest) { xmlDoc=new window.XMLHttpRequest(); xmlDoc.open("GET","data.xml",false); xmlDoc.send(""); xmlDoc=xmlDoc.responseXML; } else if (ActiveXObject("Microsoft.XMLDOM")) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("data.xml"); } var x=xmlDoc.getElementsByTagName("PR");i=0; var y=xmlDoc.getElementsByTagName("OPTION");j=0; var z=xmlDoc.getElementsByTagName("OPT");k=0; var enl; Above Code, calls on data.xml in the same folder. It then creates an array from the XML for <PR> <OPTION> and <OPT>. In the XML. It's... Code: XML <PRODUCT> <PR> <TITLE>Title goes here</TITLE> <IMG>jpg html for image goes here</IMG> <ENL>jpg html for high res image goes here</ENL> <LINK>a link if needed</LINK> <INFO>more info if needed</INFO> <OPTION> <OPT>hearts</OPT> <OPT>stars</OPT> <OPT>horseshoes</OPT> <OPT>clovers</OPT> <OPT>balloons</OPT> </OPTION> </PR> <PR> <TITLE>Title goes here</TITLE> <IMG>jpg html for image goes here</IMG> <ENL>jpg html for high res image goes here</ENL> <LINK>a link if needed</LINK> <INFO>more info if needed</INFO> <OPTION> <OPT>hearts</OPT> <OPT>stars</OPT> <OPT>horseshoes</OPT> <OPT>clovers</OPT> <OPT>balloons</OPT> </OPTION> </PR></PRODUCT> The OPT is what I want to load as an array. How could I do that? So continuing with the JS code... Code: function productnext(){if (i<x.length-5) { i++; productline();return false; }} function productprevious(){if (i>0) { i--; productline();return false; }} function productline(){ ttl1=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl2=(x[i+1].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl3=(x[i+2].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl4=(x[i+3].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); ttl5=(x[i+4].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); img1=(x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img2=(x[i+1].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img3=(x[i+2].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img4=(x[i+3].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); img5=(x[i+4].getElementsByTagName("IMG")[0].childNodes[0].nodeValue); lnk1=(x[i].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk2=(x[i+1].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk3=(x[i+2].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk4=(x[i+3].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); lnk5=(x[i+4].getElementsByTagName("LINK")[0].childNodes[0].nodeValue); inf1=(x[i].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf2=(x[i+1].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf3=(x[i+2].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf4=(x[i+3].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); inf5=(x[i+4].getElementsByTagName("INFO")[0].childNodes[0].nodeValue); opt1=(y[j].getElementsByTagName("OPT")[0].childNodes[0].nodeValue); opt2=(y[j+1].getElementsByTagName("OPT")[1].childNodes[0].nodeValue); opt3=(y[j+2].getElementsByTagName("OPT")[2].childNodes[0].nodeValue); opt4=(y[j+3].getElementsByTagName("OPT")[3].childNodes[0].nodeValue); opt5=(y[j+4].getElementsByTagName("OPT")[4].childNodes[0].nodeValue); enl1=(x[i].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl2=(x[i+1].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl3=(x[i+2].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl4=(x[i+3].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); enl5=(x[i+4].getElementsByTagName("ENL")[0].childNodes[0].nodeValue); The first two functions are for a list in the PHP. The rest of the code gives the first five products into respective variables for the PHP to use. Code: PHP <td width="25" rowspan="3"><a title="<b>Previous Product</b><br><br>Click to Scroll the product list left" onclick="productprevious();" style="cursor:pointer"><img src='prodprev.jpg' width="25" height="170"></a></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR1'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR2'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR3'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR4'></div></td> <td> </td> <td width="120" height="120" valign="top"><div id='PR5'></div></td> <td> </td> <td width="25" rowspan="3"><a title="<b>Next Product</b><br><br>Click to Scroll the product list right" onclick="productnext();" style="cursor:pointer"><img src='prodnext.jpg' width="25" height="170"></a></td> It's a line for five products. When people hit the Next button, it moves the Array one product over. And previous button does vice versa. Code: JS document.getElementById("PR1").innerHTML="<a href='javascript:void();' onClick='picture1();'><img src='"+img1+"' height=120 width=120></a>"; document.getElementById("PR2").innerHTML="<a href='javascript:void();' onClick='picture2();'><img src='"+img2+"' height=120 width=120></a>"; document.getElementById("PR3").innerHTML="<a href='javascript:void();' onClick='picture3();'><img src='"+img3+"' height=120 width=120></a>"; document.getElementById("PR4").innerHTML="<a href='javascript:void();' onClick='picture4();'><img src='"+img4+"' height=120 width=120></a>"; document.getElementById("PR5").innerHTML="<a href='javascript:void();' onClick='picture5();'><img src='"+img5+"' height=120 width=120></a>"; document.getElementById("PT1").innerHTML="<a href='javascript:void();' onClick='picture1();'>"+ttl1+"</a>"; document.getElementById("PT2").innerHTML="<a href='javascript:void();' onClick='picture2();'>"+ttl2+"</a>"; document.getElementById("PT3").innerHTML="<a href='javascript:void();' onClick='picture3();'>"+ttl3+"</a>"; document.getElementById("PT4").innerHTML="<a href='javascript:void();' onClick='picture4();'>"+ttl4+"</a>"; document.getElementById("PT5").innerHTML="<a href='javascript:void();' onClick='picture5();'>"+ttl5+"</a>"; return false;} This code places the products into the respective list. PR1 gets IMG1. This is also where I wonder if it could be more efficient, because I'm copying things five times in a row. There's got to be a better way to do that. Whenever it's clicked it operates a function called picture#() corresponding to the button. Once again... Must be a more efficient way. Code: function picture1() {document.getElementById('PI').innerHTML="<img src="+img1+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl1; /*test area, delete when done*/enl=enl1;document.getElementById("E").innerHTML=enl;} function picture2() {document.getElementById('PI').innerHTML="<img src="+img2+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl2; /*test area, delete when done*/enl=enl2;document.getElementById("E").innerHTML=enl;} function picture3() {document.getElementById('PI').innerHTML="<img src="+img3+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl3; /*test area, delete when done*/enl=enl3;document.getElementById("E").innerHTML=enl;} function picture4() {document.getElementById('PI').innerHTML="<img src="+img4+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl4; /*test area, delete when done*/enl=enl4;document.getElementById("E").innerHTML=enl;} function picture5() {document.getElementById('PI').innerHTML="<img src="+img5+" height=170 width=170>";document.getElementById('PTT').innerHTML=ttl5; /*test area, delete when done*/enl=enl5;document.getElementById("E").innerHTML=enl;} Above, places that picture into "PI" and gets the title and places it into "PTT" --- I was hoping to create another list. EXACTLY like I have here. Where the User can hit Next and Previous, using Options Loaded from an Array within the Array of Products. Is making a new XML with options the only way to do this? If that's the case, how do I associate each product with their options? How would i draw a line on a page dynamically, like if i were clicking points on a map and i wanted to link them together. How could i do that? i found this, but maybe you know of something better that would not require coordinates Hi, I was wondering - how can I convert something that a user draws inside canvas? Say, they draw a square, how could I convert that to print "You have drawn a square" - this would be posted to a text file. Thanks in advance. Hi Everyone I am trying to write some code to create an object in JS that contains the x,y coords for a shape i wish to draw. I create the shape, and then in a draw function I draw the shape to the screen from the object I created erlier. Trouble it is does not seem to work :S have anyone got and ideas? Code: var myShape = new newShape(200,200); function init() { canvas = document.getElementById("canvas"); ctx = canvas.getContext("2d"); return setInterval(draw, 50); } // init function newShape(x,y){ this.un_X=x this.un_Y=y function drawAll() { ctx.beginPath(); ctx.arc(un_X,un_Y,30,0,Math.PI*2,true); ctx.closePath(); ctx.stroke(); } // drawAll } // newShape function draw() { ctx.clearRect(0, 0, WIDTH, HEIGHT); myShape.drawAll(); } // draw init(); Thanks in advance Hi, I'm trying to put a script in my code which when an image is clicked in the webpage, i'd like it to go through the array from index 0,1,2,3, displaying the images as the current picture is clicked. Once at the end of the array, i'd like it to return to the first index (0) and do the same again. In effect, i'm trying to create a gallery of images for users to click through. I have this code, now it loads up fine, the first image loads, when I click the image, the image in index[1] loads, but when clicked again, it returns to index[0] then the same happens over and over. My code: Code: <script type="text/javascript"> var myImages = new Array() myImages[0] = 'images/homePic.png'; myImages[1] = 'images/pinkWall.png'; myImages[2] = 'images/wendy.png'; myImages[3] = 'images/horizon.png'; function imgChange(that) { var index = 0; while (that.src.indexOf(myImages[index]) != -1) { myImages[index] = myImages[index++]; } that.src = myImages[index]; return false; } </script> HTML: Code: <img src="images/homePic.png" id="pic" alt="homePic" name="bGarden" height="344px" width="490px" onclick="return imgChange(this)" /> Any advice will be greatly appreciated, thank you. Okay, so I've been trying to pick up JavaScript and JQuery. And I have a few questions, would be very grateful for answers: -If I'm making a sliding image gallery with JQuery, how do I store my images in an array? I take it this is the best way? I've made a JQuery gallery by assigning each image an ID, and hiding the ones that aren't required. This looks like bad practice though. I take it it should work with a standard JavaScript array, then reference the position of the image I've loaded? like [0][1][2] etc, but something must be amiss in my code. So basically, I've animated my image in, and there's a next button that I want to take me to the next image in the sequence. Can anyone give me a tip? Thanks a lot. Hello all, I have the following code to load a new html page into the 'new content' div once the user scrolls to the bottom of the page. It all works fine. No problems, except I would like it to pause for a moment whilst it is loading, and show a loading box div at the bottom of the screen as it loads the new content, just to give some positive feedback for the user. So the new div would sit in a fixed position at 'bottom:0px;' and have a loading image inside it. Is this easy to do? I am new to javascript so bear with me Code: alreadyloading = false; nextpage = 2; $(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { if (alreadyloading == false) { var url = "page"+nextpage+".html"; alreadyloading = true; $.post(url, function(data) { $('#newcontent').children().last().after(data); alreadyloading = false; nextpage++; }); } } }); The 'new content' is a div which is at the bottom of the page and is where the new content loads to! Thank you very much |