JavaScript - Gif Animation Sequence With Last Image Frame Being Random
Similar TutorialsI' am trying to do a frame by frame animation, lik an animated gif. I am using svg (vector graphics) and IE9 has native support for svg. The code functions in every other browser but IE9 plays the animation once then nothing. If you would like to try and not have svg files you can use whatever gif,jpg or png just put an img-tag where i have embed. Code: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Animation</title> <style type="text/css"> /*One div per image all uses this class*/ .eyesPos { position:absolute; width:80px; height:50px; z-index:1; left: 0px; top: 0px; } #eye_wrapper{/*This is a master div for easy placement of the others*/ position:absolute; width:80px; height:50px; z-index:2; left: 275px; top: 200px; } </style> <script> var eyes=["a","b","c","d"];//Image id in this array var startAnim=setInterval(visaOga,100);//Animation speed function visaOga(){ document.getElementById(eyes.splice(0,1)).style.display="block"; if(eyes.length==0){ document.getElementById("a").style.display="none"; document.getElementById("b").style.display="none"; document.getElementById("c").style.display="none"; dBort = function(){ document.getElementById("d").style.display="none"; eyes=["a","b","c","d"]; } setTimeout(dBort,1500);//So last image is shown 1.5 sec return;//Aborts - dBort -. Sequence can start over if(document.getElementById("d").style.display=="none"){ startAnim;//Strts sequence if last image invisible } } } </script> </head> <body> <!--Images in own div invisible at start--> <div id="eye_wrapper"> <div class="eyesPos" id="a" style= display:none;> <embed src="0.svg" width="80" height="50" /> </div> <div class="eyesPos" id="b" style= display:none;> <embed src="1.svg" width="80" height="50" /> </div> <div class="eyesPos" id="c" style= display:none;> <embed src="2.svg" width="80" height="50" /> </div> <div class="eyesPos" id="d" style= display:none;> <embed src="3.svg" width="80" height="50" /> </div> </div> </body> </html> Hi, I'm trying to make something along the lines of a dynamic animated GIF. In other words, I'm trying to write a script to flip through images based on the current time. Before folks start suggesting other ways to do this, know that this is just a proof of concept. The reason for doing it this way is so that I can eventually control the animation either in response to interaction or external data queries (I'm looking into that js weather api). Code: int startTime = getTime(); float speed = 1.0; image frames = new Array(); //load frames into array for(int i = 0; i < 12; i++){ frames[i] = new Image(640,480); frames[i].src = "frames/" + i + ".JPG"; } //playback int i = 0; while(i < frames.length){ if( ((getTime()-startTime) % (speed*33)) == 0){ document.currentFrame.src = frames[i].src; i++; } } Thanks, Zach I want the images to change in sequence when the page is refreshed not random like i have below. Can someone help me with this please? Also I also need text to change on refresh to because I am going to have a descritption of the image below. Thanks [CODE] <script type="text/javascript" language="JavaScript"> var imgs = new Array('<a href="VW_1.shtml"><img border=0 src="img/samples/VW/large_1.jpg" width=165 height=109" class="thumbnail_img">', '<a href="fortshelby1.shtml"><img border=0 src="img/samples/Fort Shelby/image1-large.jpg" width=165 height=109 class="thumbnail_img">', '<a href="jaguar1.shtml"><img border=0 src="img/samples/Jag_of_Novi/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="harley1.shtml"><img border=0 src="img/samples/wolverine_harley/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="bc1.shtml"><img border=0 src="img/samples/BC_Coney_Island/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="mama1.shtml"><img border=0 src="img/samples/Pozios_Retail_Mama_Vickys_Coney_Island/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="children1.shtml"><img border=0 src="img/samples/Detroit_Childrens_Museum/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="harper1.shtml"><img border=0 src="img/samples/Harper_Woods_Library/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="dps1.shtml"><img border=0 src="img/samples/DPS_Facilities_building/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="lakeland1.shtml"><img border=0 src="img/samples/Lakeland_School_Huron_Valley/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="auto1.shtml"><img border=0 src="img/samples/Manhattan_Auto_Group/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="maxey1.shtml"><img border=0 src="img/samples/Maxey_Ford/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="benz1.shtml"><img border=0 src="img/samples/Mercedes_Benz_of_St_Clair_Shores/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="metro_lofts1.shtml"><img border=0 src="img/samples/Metro_Lofts/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="mtclemens1.shtml"><img border=0 src="img/samples/Mt_Clemens_Library/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="st_gertrudes.shtml"><img border=0 src="img/samples/st_gertrudes/large_1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="rayconnect1.shtml"><img border=0 src="img/samples/Rayconnect/large 1.jpg" width=165 height=109 class="thumbnail_img">', '<a href="faulhauber1.shtml"><img border=0 src="img/samples/Faulhauber/large1.jpg" width=165 height=109 class="thumbnail_img">'); var max = imgs.length; var num = Math.floor((Math.random() * max)); document.writeln(imgs[num]); </script> [CODE] Hi! I'm very new to Javascript so first I want to apologize for my lack of knowledge, what I'm asking is probably really simple to do. Im have a folder full of images. Each image is named with an incrementing number like vidseq000001, vidseq000002, vidseq000003 and so on. I'm trying to use a jQuery plugin called "reel" to make the sequence animate. For that it seems I need to put the images inside an array. I know how to manually enter each image inside the array like var [ vidseq000001, vidseq000002, vidseq000003, ] But this becomes quite tedious with over thousand images. What would be a smarter way to put all my images inside an array? Hey All, So to start out, this is my first post on CodingForums! I've only recently started learning web development so I figured it would be a good idea to get involved with some active forums. I am trying to open a random page in a frame, but I am trying to call the Javascript to do so in another frame. I currently have an html page with a frameset which has two frames. One of the frames is a toolbar that sits at the top of the page and it has an image that acts as button. When the user clicks on this image, the bottom frame generates a random page from an array of links I have hardcoded into the Javascript. The bottom frame is just set to google.com as a default because I couldn't really think of anything to put in an html file there. The problem I'm having is when I click on the image to open a random page in the bottom frame, nothing happens. The code for all the files are below. Home.html Code: <head> </head> <frameset rows='44,*' cols="*" frameborder='no'> <frame name="toolbar" noresize="noresize" src="toolbar.htm" marginwidth="5px" marginheight="10px" scrolling="no"> <frame name="main" noresize="noresize" src="http://www.google.com" marginwidth="5px" marginheight="5px" scrolling="auto" > </frameset><noframes></noframes> <body> </body> </html> The code for the frame, toolbar.htm: Code: <head> <title></title> <script type="text/JavaScript" src="random.js"></script> </head> <body> <div id="wrapper"> <div id="toolbar"> <a href="javascript:getaPage()"><img src="Images/nextpage.png" align="right" /></a> </div> </div> </body> </html> And finally the Javascript, random.js: Code: function get_random() { var ranNum= Math.floor(Math.random()*3); return ranNum; } function getaPage() { var randomPage=get_random(); var page=new Array(3) Page[0]="http://www.google.com"; Page[1]="http://www.yahoo.com"; Page[2]="http://www.myspace.com"; top.main.location.href=page[randomPage]; } And as a follow-up question, how difficult would it be to set up this entire random page generating script via php? I'm learning php so I can eventually set up a database of urls in mysql and have tags associated with each url. Thanks in advance! How can I make a image where the first image "rolls" up and another (different) image "rolls" up from the bottom? I know how to code it except for the animation sequence. All images are 200 width and 50 height.\ Thanks in advance! (Would like to use jQuery if possible) Hi, I am looking for a script which could do picture animation like in this page But there is other problem: When you put your mouse on them, they appear colored. I need that this appearing action would take 5 seconds. 5 sek. to become colored, 5 sek. to become grey when you put away your mouse. If you need more info, ask.. Thanks a lot. Hi there, I'm having some real trouble with what I thought would be some really simple animations. I've been using, or trying to use the jQuery plugin. Basically I have a button, the mark up would probably (don't have to if anyone can come up with something better) look like this: Code: <button><span>Text in Button</span><i></i></button> I've uploaded a pic, to show (very crudely), how the animation should work: So, you have text with circle graphic on the end by default. When you hover over this element, the background should slide across. This could use another image, probably preferably, so 2 in totally, one for the left side and one for the right. As well as this animation,the text should also slide, probably just 5/10px or so across. I guess this would all animate in reverse when moving the mouse off the element. Does anyone have any ideas on this or can point me in the right direction? It would be greatly appreciated as ever. Thanks for taking the time to read, Steve Hi there, I found this thread on the forum its from a few years back but the code works, but I can't seem to get the image that appears as you rollover the button to display in the correct place. I'm not sure if its because I'm using tables within tables? Should I recode in divs? Any help is greatly appreciated!! http://www.codingforums.com/archive/...p/t-95847.html Here's what I usually use and have been using for years and it works great, just not for this particular purpose. I don't have a clue when it comes to javascript. Code: <noscript><img src="no_script_quote.gif" width="406" height="94"/></noscript><script language="javascript"> var delay=6000 var curindex=0 var images=new Array() images[0]="quote1.gif" images[1]="quote2.gif" images[2]="quote3.gif" images[3]="quote4.gif" images[4]="quote5.gif" var preload=new Array() for (n=0;n<images.length;n++) { preload[n]=new Image() preload[n].src=images[n] } document.write('<img name="defaultimage" src="'+images[Math.floor(Math.random()*(images.length))]+'">') function rotateimage() { if (curindex==(tempindex=Math.floor(Math.random()*(images.length)))){ curindex=curindex==0? 1 : curindex-1 } else curindex=tempindex document.images.defaultimage.src=images[curindex] } setInterval("rotateimage()",delay) </script> But, now I want to be able to set a default picture to be shown first and have the random pics appear next. I also don't want the default pic to show up again in the random array. So basically, every time the page was first visited, or refreshed it would show the default picture then move into the random pics. Is there anyway to modify the code that I'm using to accomplish this? Or... Any help would be appreciated. Thanks, Dell Hey folks.. Hope you can help, I'm completely new to this and have no knowledge at all when it comes to javascript. Have been using this script on my site for a while. Is there anyway I can add a URL link to the images that are in my selector? When clicked would go to that page on my website. Thanks in advance of any help Nat <script language="JavaScript"> /* Random image slideshow- By Tyler Clarke (tyler@ihatecoffee.com) For this script and more, visit http://www.javascriptkit.com */ var delay=10000 //set delay in miliseconds var curindex=0 var randomimages=new Array() randomimages[0]="http://www.anywebsite.com/images/splash1.jpg" randomimages[1]="http://www.anywebsite.com/images/splash2.jpg" randomimages[2]="http://www.anywebsite.com/images/splash3.jpg" randomimages[3]="http://www.anywebsite.com/images/splash4.jpg" randomimages[4]="http://www.anywebsite.com/images/splash5.jpg" var preload=new Array() for (n=0;n<randomimages.length;n++) { preload[n]=new Image() preload[n].src=randomimages[n] } document.write('<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">') function rotateimage() { if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){ curindex=curindex==0? 1 : curindex-1 } else curindex=tempindex document.images.defaultimage.src=randomimages[curindex] } setInterval("rotateimage()",delay) </script> Hi guys, this is my first post so be gentle. The problem I am having is this.. I want to have a link so that when you put your mouse over it, an image will be displayed in another frame. I thought this would not be as hard as it has been other wise i would not be turning to you for help. this is the link right now: <a href="http://www.dickblick.com/zz529/47/" rel="nofollow" target="_blank">Alvin 4-Piece Creative Center</a> its just a standard link. the image is located at /images/alvin_wood.jpg here is what I have tried so far.. I have tried using the window.open command and that seemed to work but i could not get it to open in a size of my determiation.. ie 200 by 300 (random demensions i just threw out). ive tried this: <a href="javascript: onMouseOver="window.open('images/picture.jpg')"> Ive tried using the showtrail and hide trail functions ( i think they are functions), and a slew of others but i got mad and deleted it... i prolly shouldnt have done that.. but ill find it and post it so you can see. http://www.stockxpert.com/browse.phtml?f=s&c=100 that is what i want to do except starting off it would be the link and then the image would pop up... I dont even care if its in another frame.. I can take that frame out its not a bid deal.. ive been screwing with this for two weeks and this is my last bit of effort to find an answer.. SO!! if anyone can help I would be greatful!! THANK YOU! Hi Im trying to creat a website so when the small image is rolled over a new page opens in the frame ( called main) i will upload it now to http://www.e-z-host.com/GZ/ all help apricated ! at the momment you have to click to open the page in the main frame. Does anyone have a script, that can display a random image of the images I select?I'm going to use it for a type of captcha. I think this would be easier in javascript, so yes I am in the right section.
I have 3 background images, and 1 is picked at random to be the background image of the body when loading the page.My code is below. Right now it's just white, can't get any pictures to load. I have checked the URLs and they are correct. Can someone help out? Here is my code in the header: Code: <script type="text/javascript"> function getBackground(){ var bgimg = new Array(); bgimg[0] = "background1"; bgimg[1] = "background2"; bgimg[2] = "background3"; var random = Math.floor(Math.random() * bgimg.length); var imgurl = bgimg[random]; document.body.style.backgroundImage = 'url(' + imgurl + ')'; } </script> body: Code: <body onload="getBackground()"> Forgive me if this is in the wrong forum as I am unsure as to whether this should be PHP or Java, or a WP plugin. Basically I need to have a slideshow that picks images from a folder without the need to use arrays as there will be a large amount of images and I need to literally be able to drop images in a folder and they appear in a random order within the slideshow. As you can appreciate with a large amount of images, the code needs to call them as and when needed rather than loading them in at the beginning. I have been using Wordpress's nextgen gallery and have been hacking away at a few plugins etc, and the closest I have come is to make WP select a different post with gallery each time creating the illusion that the images are in a different order, however this isn't going to be ideal as its not truly random, and breeds duplicates. If I have to stay away from WP that's fine, uploading to an ftp would be ok. Hope someone can point me in the right direction! Thank You A I have a tutorial I have to complete for my web class out of the "New Perspectives HTML, XHTML, and Dynamic HTML 4th edition book" (the tutorial I'm doing is number 10) and I can't figure out how to get the numbers to show up. Here is the code that is given to start out with. Code: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- New Perspectives on HTML and XHTML 5th Edition Tutorial 10 Review Assignment Monroe Public Library Author: Date: Filename: mpl2.htm Supporting files: mpl2.jpg, mplstyles.css, random.js, 0.jpg - 9.jpg --> <title>Monroe Public Library</title> <link href="mplstyles.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <div id="head"> <img src="mpl.jpg" alt="Monroe Public Library" /> </div> <div id="links"> <span>Quick Links</span> <a href="#">Home Page</a> <a href="#">Online Catalog</a> <a href="#">Friends of MPL</a> <a href="#">New Books and Other Good Reading</a> <a href="#">Ohio Virtual Library</a> <a href="#">Internet Public Library</a> <a href="#">Services and Collection</a> <a href="#">Adult Programs</a> <a href="#">Teen Central</a> <a href="#">Children's Room</a> <a href="#">Computers at MPL</a> <a href="#">Computer Rules and Procedures</a> <a href="#">Staff Directory</a> <a href="#">Library Records</a> </div> <div id="main"> <h2>Library Records</h2> <p>To view the library records, enter your username and password.</p> <table border="1" cellpadding="5" cellspacing="0"> <tr> <th>Username</th> <td><input size="20" /></td> </tr> <tr> <th>Password</th> <td><input type="password" size="20" /></td> </tr> <tr> <td>As a final security check, enter the 5 numbers you see displayed below.</td> <td><input size="6" /></td> </tr> <tr> <td colspan="2" class="center"> <input type="button" value="View Library Records" /> </td> </tr> <tr> <td colspan="2" class="center"> </td> </tr> </table> </div> <address> <b>Monroe Public Library</b> 580 Main Street, Monroe, OH 45050 <b>Phone</b>(513) 555-0211 <b>Fax</b>(513) 555-0241 </address> </div> </body> </html> Then these are the directions given in the book. 1. In the head section, just above the closing </head> tag, insert a script element that accesses the code in the random.js file. 2. add a second script element for the cod e that you'll add to the mpl2.htm file 3. Within the second script element, create a function named showImg(). The purpose of this function is to write an inline image tag into the current document. The function has no parameters. Add the following statements to the function: a. Add the following multiline comment to the start of the function, just below the opening showImg() function statement. The showImg() function displays a random image from the 0.jpg through 9.jpg files. The random image is designed to thwart hackers attempting to enter the library records database by requiring visual confirmation. b. Declare a variable named imgNumber equal to the value returned by the randomInteger() function. Use 9 as a value of the size parameter in the randomInteger() function. c. append the statement that creates the imgNumber variable with the following single-line comment: Return a random number from 0 to 9 d. inster a command that writes the text <img src='imgNumber.jpg' alt='' /> to the document, where imgNumber is the value of the imgNumber variable. 4. scroll down to the bottom of the file and locate the last table cell in the document. Within this empty table cell, insert a script element. 5. within the script element, call the showImg() function five times. YOu do not need to specify a parameter value. ___________________________ It's a lot of info but I just can't figure out how to get the images to show up, any help will be appreciated, I think I gave all the info needed. Hi, please look at: http://bit.ly/hO5VBE then click 'play app match' you'll see the images are taken from the first 15 in an array, then doubled and randomized. however, i want the the images taken to be a random selection from an array of 15+ images. so the array would be e.g. 25 images, and i want any 15 of those 25 to be chosen (then doubled and randomized) rather than the first 15 taken. any help would be great! James p.s. if you load the main page while hovering over an icon, its tooltip will be "undefined".. any ideas to stop this? Thanks! Hi, im wondering if anyone can help me, i have a random image script and it works fine, apart from when you click on the images they link to the right place but ALL go to _self I want [2],[3]and[6] to link to the places they are already linking to but _blank NOT _self, does anyone know how to do this, it would be a massive help :) Below is the code for the script i am using: Code: <script language="JavaScript"> function random_imglink(){ var myimages=new Array() //specify random images below. You can have as many as you wish myimages[1]="images/layout/bottom gallery.png" myimages[2]="images/layout/bottom facebook.png" myimages[3]="images/layout/bottom twitter.png" myimages[4]="images/layout/bottom team.png" myimages[5]="images/layout/bottom whats on.png" myimages[6]="images/layout/bottom forum.png" //specify corresponding links below var imagelinks=new Array() imagelinks[1]="gallery.html" imagelinks[2]="http://www.facebook.com/tos.php?api_key=fcddbaae811ef62bf3c4fb2ac7b1fd07&next=http%3A//dailyphoto-1402445175.us-east-1.elb.amazonaws.com/dailyphoto/applications/buffer/id%3A1/pid%3A2828044108236222753/from%3Apublisher.attachment.own.image?ref=nf&v=1.0&canvas#/group.php?gid=87957825200&ref=ts" imagelinks[3]="https://twitter.com/groundzereo" imagelinks[4]="team.html" imagelinks[5]="whatson.html" imagelinks[6]="http://groundzero.forumotion.co.uk/" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>') } random_imglink() //--> </script> Thanks in advance =) |