JavaScript - Onmouseover And After Mouse Over - Stop The Animation, Best Way
for example i have:
a picture of a man sitting down a gif of him going from the sitting position to the standing position and picture of him standing i want the man to sit when the page is loaded, go to the standing animation onMouseOver, and when the animation is complete, stop the animation by going to the standing picture i have heard of two ways to do this but i dont know the best way, or if there is a third alternative with PHP or another language i could make a timer of the same period of time it takes for the standing gif to complete. i havent done any testing but i would suspect that there would be a bug with this method. some older computers load slower, and the gif may finish its animation before the timer is complete, or the timer may complete before the gif has finished its animation. this might cause gif to start a new cycle before the browser changes pictures, or the browser might change pictures before the man is finished standing. if you know for a fact that this will not happen, or if its occurrence is extremely rare, please alleviate my fears the second option is to break the gif down with some piece of software into jpegs and make many timers to reassemble the animation. this method was not suggested to me, i came up with it myself, so i dont trust that this is the best way to do things properly anyone who has ever done this sort of rollover animation in any language, your input would be greatly appreciated Similar Tutorialson this site. There are no validation errors. firebug says my linkOut function is not defined... but I have this: Code: function linkOut(link) { var image = link.getElementsByTagName("IMG")[0]; image.src = image.src.replace("H2.png","H.png"); } not sure where to go from here. Hi I am new here, am having a terrible problem with animation build up. have searched and found various codes to stop,but can't implement in the .js in a way that works. Maybe am putting in wrong place. Wondering if anyone can help, would really appreciate it. Following is the code: Thank you Code: var droplinemenu={ arrowimage: {classname: 'downarrowclass', src: 'down.gif', leftpadding: 5}, //customize down arrow image animateduration: {over: 200, out: 600}, //duration of slide in/ out animation, in milliseconds buildmenu:function(menuid){ jQuery(document).ready(function($){ var $mainmenu=$("#"+menuid+">ul") var $headers=$mainmenu.find("ul").parent() $headers.each(function(i){ var $curobj=$(this) var $subul=$(this).find('ul:eq(0)') this._dimensions={h:$curobj.find('a:eq(0)').outerHeight()} this.istopheader=$curobj.parents("ul").length==1? true : false if (!this.istopheader) $subul.css({left:0, top:this._dimensions.h}) var $innerheader=$curobj.children('a').eq(0) $innerheader=($innerheader.children().eq(0).is('span'))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that $innerheader.append( '<img src="'+ droplinemenu.arrowimage.src +'" class="' + droplinemenu.arrowimage.classname + '" style="border:0; padding-left: '+droplinemenu.arrowimage.leftpadding+'px" />' ) $curobj.hover( function(e){ var $targetul=$(this).children("ul:eq(0)") if ($targetul.queue().length<=1) //if 1 or less queued animations if (this.istopheader) $targetul.css({left: $mainmenu.position().left, top: $mainmenu.position().top+this._dimensions.h}) if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow $mainmenu.find('ul').css({overflow: (this.istopheader)? 'hidden' : 'visible'}) $targetul.slideDown(droplinemenu.animateduration.over) }, function(e){ var $targetul=$(this).children("ul:eq(0)") $targetul.slideUp(droplinemenu.animateduration.out) } ) //end hover }) //end $headers.each() $mainmenu.find("ul").css({display:'none', visibility:'visible', width:$mainmenu.width()}) }) //end document.ready } } I have a piece of raw code. I want to make some images greater/smaller onmouseover/onmouseout, in a graduate mode, on using some independent setTimeout objects which are to be started/clear . It works ok if the mouse goes up and down at a reasonable speed. But if the movement is fast, the onmouseout looks to fail in firing (and some images remain on their bigger stage), which is somehow weird. Where could be the mistake? What did I make wrong (except that I might have had done that with Flash)? Any thoughts? You have in the attachment (see test.zip) the full example, with the used images, as well. Code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <style type="text/css"> img{ width:144px; height:36px; cursor:pointer; } </style> <script type="text/javascript"> var big1,big2,big3,small1,small2,small3, step=1; function bigPic1(obj,w,h){ w+=4;h++; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h<55){big1=setTimeout(function(){bigPic1(obj,w,h)},step)} } function smallPic1(obj,w,h){ w-=4;h--; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h>36){small1=setTimeout(function(){smallPic1(obj,w,h)},step)} } function bigPic2(obj,w,h){ w+=4;h++; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h<55){big2=setTimeout(function(){bigPic2(obj,w,h)},step)} } function smallPic2(obj,w,h){ w-=4;h--; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h>36){small2=setTimeout(function(){smallPic2(obj,w,h)},step)} } function bigPic3(obj,w,h){ w+=4;h++; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h<55){big3=setTimeout(function(){bigPic3(obj,w,h)},step)} } function smallPic3(obj,w,h){ w-=4;h--; obj.style.width=w+'px'; obj.style.height=h+'px'; if(h>36){small3=setTimeout(function(){smallPic3(obj,w,h)},step)} } function setAtt(){ var allImg=document.getElementById('menu').getElementsByTagName('img'), img, i=0; while(img=allImg[i++]){ img.style.width='144px'; img.style.height='36px'; img.ind=i; img.onmouseover=function(){ if('small'+this.ind){clearTimeout('small'+this.ind)}; window['bigPic'+this.ind](this,parseInt(this.style.width),parseInt(this.style.height)) }; img.onmouseout=function(){ if('big'+this.ind){clearTimeout('big'+this.ind)}; window['smallPic'+this.ind](this,parseInt(this.style.width),parseInt(this.style.height)) }; } } onload=setAtt </script> </head> <body> <div id="menu"> <div> <img src="01.png" width="144" height="36" border="0" alt=""> </div> <br> <br> <div> <img src="02.png" width="144" height="36" border="0" alt=""> </div> <br> <br> <div> <img src="03.png" width="144" height="36" border="0" alt=""> </div> </div> </body> </html> Hey CodingFourm-ites! Ive scoured the internet for scripts that make a <div> follow the mouse, and have found one that seems to work well. However, I want the <div> to stop moving when the CTRL or the SHIFT key is pressed, I dont care which. Hopefully, I can have a div that follows the mouse at an offset that contains some click-able items, so a menu is always by your mouse. Ive tried now more than a few times to put together a piece of code that can achieve this, but none have worked. Can somebody write a script that can achieve this, or point me in the right direction? Thanks guys! Current JS for mouse follow: Code: var divName = 'mouseFollow'; // div that is to follow the mouse // (must be position:absolute) var offX = 15; // X offset from mouse position var offY = 15; // Y offset from mouse position function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;} function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;} function follow(evt) {if (document.getElementById) {var obj = document.getElementById(divName).style; obj.visibility = 'visible'; obj.left = (parseInt(mouseX(evt))+offX) + 'px'; obj.top = (parseInt(mouseY(evt))+offY) + 'px';}} document.onmousemove = follow; The original code can be found at: http://javascript.about.com/library/blfollow2.htm Hello all, I have a question regarding onmouseover on "a" tag. I currently have a list of "img" thumbnails which have onMouseOver attached to the "a" tag which wraps the "img". When the mouse is over the image, a "preview" of the image will load in another div via a javascript function, this javascript function has a jquery fadeto effect so the preview will fade into view. The problem now is if a user hover over multiple thumbnails quickly, the onMouseOver event is registered multiple times, so when the user finally stop hovering over multiple thumbnails quickly, the last thumbnail will receive the event multiple times and fades in not only once. Below is my code: function previewimage(loadimg){ jloadimg='<img src="../images/'+loadimg+'.png" />'; //stimulate a fade in effect by making the image has 0.7 opacity first $(#largeimage).fadeTo('fast', 0.7, function() { }); $(#largeimage).fadeTo('slow', 1, function() { }); document.getElementById('largeimage').innerHTML=jloadimg; } for the list of thumbnail images, I have: <a onMouseOver="previewimage('imagefile1');"><img src="path/to/thumbnail/image1.png" /></a> <a onMouseOver="previewimage('imagefile2');"><img src="path/to/thumbnail/image2.png" /></a> <a onMouseOver="previewimage('imagefile3');"><img src="path/to/thumbnail/image3.png" /></a> How do I cancel multiple event from running continuosly if the previous one is still in queue? JavaScript Code: window.addEvent('domready',function(){ //SAMPLE 8 var handles8_more = $$('#handles8_more span'); var nS8 = new noobSlide({ box: $('box8'), interval: 5000, autoPlay: true, items: $$('#box8 h3'), size: 900, handles: $$('#handles8 span'), handle_event: 'mouseenter', addButtons: { previous: $('prev8'), play: $('play8'), stop: $('stop8'), playback: $('playback8'), next: $('next8') }, onWalk: function(currentItem,currentHandle){ //style for handles $$(this.handles,handles8_more).removeClass('active'); $$(currentHandle,handles8_more[this.currentIndex]).addClass('active'); //text for "previous" and "next" default buttons $('prev8').set('html','<< '+this.items[this.previousIndex].innerHTML); $('next8').set('html',this.items[this.nextIndex].innerHTML+' >>'); } }); //walk to item 0 witouth fx nS8.walk(0,false,true); }); html Code: <div class="slider sample8"> <p class="buttons" id="handles8"> <span>Item 1</span><span>Item 2</span><span>Item 3</span><span>Item 4</span><span>Item 5</span> </p> <div class="mask1"> <div id="box8"> <div onMouseOver="nS8.Stop();" onMouseOut="nS8.Play();"> </div> </div> </div> <p class="buttons"> <span id="prev8"><< Previous</span> | <span id="next8">Next >></span> </p> <p class="buttons"> <span id="playback8">< Playback</span> <span id="stop8">Stop</span> <span id="play8">Play ></span> </p> </div> All I need to do is when they hover ocer the div statement stop the program from looping. and then when they stop hovering over it let it start looping again. I've got to have a typo somewhere, but i can't seem to find it. I need a new pair of eyes to point it out for me. background: trying to code a mouseover link for a nav bar. everything is working( hyperlink, normal image shows up) but when i mouse over the image swap doesn't happen. I have 2 parts of code. 1st preloads images and does the swap function. loads in <head> See below: Code: <SCRIPT language="javascript" type="text/javascript"> if (document.images) { /* preload images */ var subcontractorsOn = new Image (); subcontractorsOn.scr = "subcontractorsOn.gif"; var subcontractorsOff = new Image (); subcontractorsOff.scr = "subcontractorsOff.gif"; } function mouseOn (imgName) { if (document.images) document [imgName].scr = eval (imgName + "On.scr"); } function mouseOff (imgName) { if (document.images) document [imgName].scr = eval (imgName + "Off.scr"); } </SCRIPT> 2nd just calls the functions to preform the swap. this is in the <body> see code below Code: <a href="subcontractors.htm" onMouseOut="mouseOn('subcontractors')" onMouseOver="mouseOff('subcontractors')"> <img src="subcontractorsOff.gif" height="40" width="133" name="subcontractors" id="subcontractors" border="0" alt="subcontractors"></a> any insight would be great. regards, Fatmann66 I have a picture of a pinwheel on my website that I want to spin onMouseover. Can this be done with JavaScript?
Hi, I have created an animation exercise for an eLearning lesson in a program that uses JavaScript as the scripting for a Windows executable. A retired social worker who creates these eLearning materials as give-away's to help people in the community improve health, it would be a big help to reaching more people if instead of a Windows executable version, the animation could be developed in a web page. A lot more people could view the eLearning and try this exercise which trains people in pacing their breathing. The animation has a 300X300 circle on the canvas with a couple of text input boxes and a start button. The JS < 50 lines of script, but since it was not developed for a web page, it has no tags and it depends on objects like the circle or button (or 2 audio files to create the inhale/exhale sounds) that were already placed on the canvas in the Windows executable program. I'm not very skilled using Dreamweaver CS5, but with help, reading, references can try to convert this JS into a web version, if it's possible. Not sure how to do this and would appreciate any help. I am adding a screenshot of the interface and the JS functions that are called by the start button. //JS: ( bar1 is the variable entered by the use as breaths per minute-BPM; //time1 is the exercise length; the variables initially are set as follows: //time1=15, //volume=100) var time1 function minuteTimer() { breakLoop = false stopLoop = false fork (calcBreathing) for (var i=0;i<time1;i++) { wait(60) breakLoop = true Submit.Show() Text122.Show() Text12.Show() TextInput22.Show() TextInput2.Show() Submit2.Hide() TextInput2.SetTransparency(0,false) TextInput22.SetTransparency(0,false) Text12.SetTransparency(0,false) Text122.SetTransparency(0,false) Text5.SetTransparency(0,false) Frame12.SetTransparency(0,false) Submit.SetTransparency(0,false) TextInput2.Enable(true) TextInput22.Enable(true) Debug.trace("\n minutes elapsed "+(i+1)+"\n") } stopLoop = true } function calcBreathing() { var bar2 = 60/bar1 for (loop = 0;loop<bar1;loop++) { mySound.Play(1,volume) Vector8.Scale(.5,.5, bar2*.3) mySound.Stop() wait (bar2*.05) mySound2.Play(1,volume) Vector8.Scale(-.5,-.5,bar2*.6) mySound2.Stop() wait (bar2*.05) if (breakLoop) break } breakLoop = false if (bar1 > 6) bar1-- if (!stopLoop) calcBreathing() } Any help appreciated. Thanks very much. Kind Regards, saratogacoach I want to create some type of seasonal feel on my Web page where there are falling leaves. I presently have 6 different gif images of leaves that I know I will probably have to load into an array. I also know that I will have to figure out the maximum width & height of the screen, which is different in Internet Explorer and other browsers. My goal is to load the leaves randomly as well using 'Math.floor(Math.random()*6)', if that is correct. Beyond that, I am lost on how to manipulate the Web page to make this animation occur. Any help would be appreciated. Thank you. Code: <!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> <title>Autumn</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> <!--Hide from incompatible browsers /* <![CDATA[ */ var widthMax=0; var heightMax=0; var leavesLoaded = new Array(6); for (var i=0; i<6; ++i) { leavesLoaded[i] = new Image(); leavesLoaded[i].src = "leaf" + (i+1) + ".gif"; } function setLeaf() { if (navigator.appName == "Microsoft Internet Explorer") { widthMax=document.documentElement.clientWidth; heightMax=document.documentElement.clientHeight; } else { widthMax=window.innerWidth-14; heightMax=window.innerHeight; } setTimeout('fallingLeaves()',400); } /* ]]> */ // Stop hiding from incompatible browsers --> </script> </head> <body onload="setLeaf();" > <p><img src="images/leaf1.gif" id="leaf" style="position:absolute; left:0px; top:0px; visibility:hidden" alt="Image of a Leaf" /></p> </body> </html> Hi, I created JavaScript animation and the picture after animation finished disappear. Could anyone tell me or point me how to resolve this kind of issue? I tested it in IE as well as Firefox.. I could send the code but it is quite long for posting, but the screenshots from before and after animation is finished are as below. thanks in advance for any help. trotsky Hi, I will really appreciate if someone could take a look at my code below and inform me where I'm going wrong, because I can't seem to tell. The instructions a -the file starts with the text "Avalon Books" on the left edge of the page. -the text moves to the center of the page. -After the text reaches the center, the image file kids.jpg appears -Every two seconds thereafter, the image file is swapped with the next image file in the stack (there are 3 images in total). I am only posting the few relevant functions where the problem could be. All the other functions are working properly. I am new to JavaScript so any help will be really appreciated. Thank you This is the main file: Code: function placeObjects(){ var W = (0.5)*winWidth(); //gets the width of user's browser. placeIt("avalon",0,0); //placeIt function is working fine. placeIt("kids",W-75,100); placeIt("fiction",W-75,100); placeIt("nfiction",W-75,100); setZ("kids",3); //setZ function is below. setZ("fiction",2); setZ("nfiction",1); moveAvalon(); } function moveAvalon(){ var x = xCoord("avalon"); if(x <= (W-125)){ shiftIt("avalon", 10, 0); setTimeout("moveAvalon()",50); } else swapImages(); //if x is greater than W-125 } function swapImages(){ showIt("kids"); showIt("fiction"); showIt("nfiction"); setTimeout("swapIt(kids,fiction,nfiction)",2000); //syntax could be wrong here? } </script> </head> <body onload="placeObjects()"> //calls the first function on load. ............... </body> </html> and here is the second file that contains all the functions (I am posting 2 of those functions): Code: function setZ(id, z){ var object=document.getElementById(id); object.style.zIndex="z"; } function swapIt(id1, id2, id3){ var object1=getObject(id1); var object2=getObject(id2); var object3=getObject(id3); var z1; var z2; var z3; object1.style.zIndex="z1"; object2.style.zIndex="z2"; object3.style.zIndex="z3"; object1.style.zIndex="z3"; object2.style.zIndex="z1"; object3.style.zIndex="z2"; } I am having some difficulty with this project. It is supposed to be an animation of falling leaves. I am very new to arrays and JavaScript, so right off the bat I know that the arrays I have are not right, or are missing something else in order for it to function. Basically all I have for this project is a still picture of the leaves and that is it. If there is someone out there with some JavaScript expertise, could you tell me what I am doing wrong? Here is the code so far, I think it is too long. Code: <script type="text/javascript"> /* <![CDATA[ */ grphcs=new Array(6) Image0=new Image(); Image0.src=grphcs[0]="images/leaf1.gif"; Image1=new Image(); Image1.src=grphcs[1]="images/leaf2.gif"; Image2=new Image(); Image2.src=grphcs[2]="images/leaf3.gif"; Image3=new Image(); Image3.src=grphcs[3]="images/leaf4.gif"; Image4=new Image(); Image4.src=grphcs[4]="images/leaf5.gif"; Image5=new Image(); Image5.src=grphcs[5]="images/leaf6.gif"; var minSpeed = 5; var maxSpeed = 30; var randomSpeed = 5; var randomSpeed2 = 10; var randomSpeed3 = 15; var randomSpeed4 = 20; var randomSpeed5 = 25; var randomSpeed6 = 30; var minHorizontal = 200; var maxHorizontal = screen.availWidth - 300; var leftPosition = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); var leftPosition2 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); var leftPosition3 = Math.floor(Math.random() * (maxHorizontal - minHorizontal +1)) + minHorizontal); var leftPosition4 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var leftPosition5 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var leftPosition6 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var minVertical = 50; var maxVertical = screen.availHeight - 300; var topPosition = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition2 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition3 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition4 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition5 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition6 = Math.floor(Math.rnadom() * (maxVertical - (minVertical + 1)) + minVertical); function matchLeaf() { if (navigator.appName == "Microsoft Internet Explorer") { widthMax = document.documentElement.clientWidth; heightMax = document.documentElement.clientHeight; } else { widthMax = window.innerwidth - 14; heightMax = window.innerHeight; } autumnFall(); } function autumnFall(); var fallingLeaf1 = document.getElementById("leaf1"); fallingLeaf1.style.left = leftPosition + "px"; fallingLeaf1.style.top = topPosition + "px"; fallingLeaf1.style.visibility = "visible"; topPosition += parseInt(randomspeed); leftPosition += 0; if (topPosition >= screen.availHeight - 300) { topPosition = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf1.src = "images/leaf" + Math.floor(Math.random() * 6 + ".gif"; randomSpeed = Math.floor(Math.random() * maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf2 = document.getElementById("leaf2"); fallingLeaf2.style.left = leftPosition2 + "px"; fallingLeaf2.style.top = topPosition2 + "px"; fallingLeaf2.style.visibility = "visible"; topPosition2 += parseInt(randomSpeed3); leftPosition2 += 0; if (topPosition2 >= screenavailHeight - 300) { topPosition2 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition2 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf2.src = "images/leaf" + Math.floor(Math.random() * 6) + "gif"; randomSpeed2 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf3 = document.getElementById("leaf3"); fallingLeaf3.style.left = leftPosition3 + "px"; fallingLeaf3.style.top = topPosition3 + "px"; fallingLeaf3.stye.visibility = "visible"; topPosition3 += parseInt(randomSpeed3); leftPosition3 += 0; if (topPosition3 >= screen.availHeight - 300) { topPosition3 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition3 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf3.src = "images/leaf" + Math.floor(Math.random() * 6 + "gif"; randomSpeed3 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf4 = document.getElementById("leaf4"); fallingLeaf4.style.left = leftPosition4 + "px"; fallingLeaf4.style.top = topPosition4 + "px"; fallingLeaf4.style.visibility = "visible"; topPosition4 += parseInt(randomSpeed4); leftPosition4 += 0; if (topPosition4 >= screen.availHeight - 300) { topPosition4 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition4 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf4.src = "images/leaf" + Math.floor(Math.random() * 6 + "gif"; randomSpeed4 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf5 = document.getElementById("leaf5"); fallingLeaf5.style.left = leftPosition5 + "px"; fallingLeaf5.style.top = topPosition5 + "px"; fallingLeaf5.style.visibility = "visible"; topPosition5= parseInt(randomSpeed5); leftPosition5 += 0; if (topPosition5 >= screen.availHeight - 300) { topPosition5 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition5 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf5.src = "images/leaf + Math.floor(Math.random() * 6 + "gif"; randomSpeed5 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf6 = document.getElementById("leaf6"); fallingLeaf6.style.left = leftPosition6 + "px"; fallingLeaf6.style.top = topPosition6 + "px"; fallingLeaf6.style.visibility = "visible"; topPosition6 = parseInt(randomSpeed6); leftPosition6 += 0; if (topPosition6 >= screen.availHeight - 300) { topPosition6 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition6 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf6.src = "images/leaf + Math.floor(Math.random() * 6 + "gif"; randomSpeed6 = Math.floor(math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } } /* ]]> */ </script> </head> <body onload="setInterval('matchLeaf()', 100);"> <img id="leaf1" src="images/leaf1.gif" alt="leafone" style="position:absolute; left:100px; top:100px;" /> <img id="leaf2" src="images/leaf2.gif" alt="leaftwo" style="position:absolute; left:100px; top:100px;" /> <img id ="leaf3" src="images/leaf3.gif" alt="leafthree" style="position:absolute; left:100px; top:100px;" /> <img id="leaf4" src="images/leaf4.gif" alt="leaffour" style="position:absolute; left:100px; top:100px;" /> <img id="leaf5" src="images/leaf5.gif" alt="leaffive" style="position:absolute; left:100px; top:100px;" /> <img id="leaf6" src="images/leaf6.gif" alt="leafsix" style="position:absolute; left:100px; top:100px;" /> Anyone got any suggestions on techniques? The main one I find is to use translate to move the canvas around, which just seems odd to me. I don't even fully understand how it works. But the one I was looking at used clearRect. In examples given looked as though it had to redraw the canvas every frame. I'm just mucking around with a simple poker game, figured i'd have the table in one layer and anything that moves on a top layer? By doing that I could only clear each card as it moved around...yes? Anyone know of a better way of doing things? Hello readers! I made some animation code Code: for (var i = 1; i < 8; i++) { var slc = ".s" + i; $(slc).css( { 'position':'absolute', 'top':'-300px', 'left':30*i*5, 'width':'100px', 'height':'300px', 'backgroundColor':'white' }); }; $('body').click(function() { for (var t = 1; t < 8; t++) { var asd = '.s' + t; $(asd).animate({ 'top':'0px' }, 100*t).animate({ 'top':'-300px' }, 100*t); }; }); in html there are some div tags. So, question is - How to normilize queue of animation? You see that first box moves fast and the last one moves very slow to the end. I would like boxes to move proportionally in relation to the time. Could you give some recommendations about this stuff? I have a site with a lot of animated gifs and I was wondering if there was a way to (on page load) stop all gif animations (only show first image frame). Then when you click a link, it will animate the animated gifs.
I have created an animation API, which has an option for the 'effect' or animation type. Now i'm trying to produce a slow, fast slow effect using a sine wave but seem to be having some trouble! The code below is supposed to get the steps to calculate each frame by diving the usable part of the sine wave into the total frames. The code should then go on to calculate insert the relevant values into the frame variables, after which multiply them all so that they are the correct scale so that when the animation is running it simply looks up the value and applies it, no need for any processing. With an animation from 0 to 740 (px in this case) the function returns: 115, 228, 335, 434, 523, 598, 659, 703, 730, 740 Oh and just a quick addition the variable "end" will equal 740 in the case above, or whatever the end value is. Code: case "SFS": var step = 90 / totalFrames; var pi = Math.PI; var raid = 0; for (var i = 1; i <= totalFrames; i++){ raid = (i*step)*(pi/180); queueFrameValue[topOfQueue][i] = Math.sin(raid); } var multiplier = end / queueFrameValue[topOfQueue][totalFrames]; for (var i = 1; i <= totalFrames; i++){ queueFrameValue[topOfQueue][i] = queueFrameValue[topOfQueue][i] * multiplier; } break; Thanks! Hi, can someone look at my code and tell me why the animated GIF doesn't display? It is a rollover button and it's done in javascript. The mouseover file is profileani.gif. The image displays but it doesn't do the animation. The site is http://www.creationindex.com/indextest22.html If you just move the mouse around on the screen you'll see the rollover. Thank you.
Hi everyone! I'm new to coding and need help on my school project. I have to animate a ball and make it move up and down the page using the if statement and the or logic. I understand the concepts of the if statement but when it comes to actually writing it in code, I fail miserably at it. Heres the code... Code: <html> <body> <center><button type="button"onClick="first()">Click to move ball down!</button> <button type="button"onclick="second()">Click to return ball to top!</button></center> <IMG ID="ball"STYLE="position:absolute;left:50;top:50;width:100;height:100;"SRC="ball.jpg"> <script language="JavaScript"> var myElement=document.getElementById("ball"); var loc= 50; function first() { loc +=50; myElement.style.top=loc; } setInterval("first()",50); function move() { if(loc>500 || loc<0) { loc=-loc; } myBall.style.top=loc; } </script> </body> </html> .. so what is happening is the ball will continuously fall without stopping. Can someone help me get the ball bounce from the edge of the screen back to the top and continue to do it. Thanks. Hi all, I'm new to Javascript, and having an issue with getInterval. For my programming languages class we have to create a simulation of waves breaking on a shore from above. I've decided to use a canvas object and Javascript for this animation, but am getting stuck on refreshing the frames. Here is the code I have so far: Code: var shoreline = new Array(); var waves = new Array(); var canWidth = 600; var canHeight = 400; var waveNum = 0; var count = 0; function wave() { setupShore(); var canvas = document.getElementById("canvas"); canvas.setAttribute("width",canWidth); canvas.setAttribute("height",canHeight); var ctx = canvas.getContext("2d"); createWave(); setInterval(update(ctx), 1000); } function update(ctx) { if(waves.length != 0) { drawWater(ctx); drawShore(ctx); drawWaves(ctx); updateWaves(); } } function drawElement(ctx, x, y, width, height, fillcolor) { ctx.fillStyle = fillcolor; ctx.fillRect(x, y, width, height); } function setupShore() { for(var i = 0; i <= canWidth/5; i++) { shoreline[i] = Math.round(canHeight/5); // + Math.floor(Math.random()*101); } } function createWave() { /* Wave array setup: [ [waveID1, [node1, node2, ..., nodeN]], [waveID2, [node1, node2, ..., nodeN] ] */ waves.push([waveNum, []]); for(var c = 0; c <= canWidth/5; c++){ waves[waves.length-1][1].push(canHeight); } waveNum = waveNum + 1; } function destroyWave() { waves.shift(); } function drawWater(ctx) { drawElement(ctx, 0, 0, canWidth, canHeight, "#336699"); } function drawShore(ctx) { for(var s = 0; s <= shoreline.length; s++) { drawElement(ctx, s*5, 0, 5, shoreline[s], "#FFCC00"); } } function updateWaves() { for(var u = 0; u < waves.length; u++) { var limit = waves[u][1].length; for(var v = 0; v < limit; v++){ var temp = waves[u][1][v]-5; waves[u][1][v] = temp; if(waves[u][1][v] <= shoreline[v]){ destroyWave(); } } } } function drawWaves(ctx) { for(var w = 0; w < waves.length; w++) { for(var n = 0; n <= waves[w][1].length; n++){ y = waves[w][1][n]; drawElement(ctx, n*5, y, 5, 5, "Purple"); } } } As you can see, the idea is that each 5-pixel wide node of the shore and wave are stored in arrays so that the position of each node can differ. The wave() function initializes all the required data, and then calls setInterval on update(). The function update() draws the water, shore, and wave, and then updates the wave position node-by-node. Ideally, setInterval would cause this to happen repeatedly, so that the wave would appear to move closer to the shore every 1000ms. However, this is not the case. It appears as though setInterval is working for one pass of update(), but fails after the first pass. You can tell that this is happening because the wave appears at its starting position, but does not continue to move. Any idea why this is happening? I read somewhere that setInterval can be broken by one-time functions, but I'm not sure. If you'd like to see what it's currently doing in a browser, I've hosted it here. Once I've got this animating properly I can continue my project, but I've hit a roadblock. Thanks in advance for your help, I'm really stuck. Marcus |