JavaScript - Javascript Motion Tween
I have a javascript slideshow and I can't seem to get the thumbnail motion tween to be smooth and consistent on all browsers.
the entire script is on one single HTML file. here is a link to it: http://www.mediastream247.com/temp/ss9.html somebody please help. I have been trying for weeks to figure this out and have searched all over the internet, but still no solution. it's slow on IE and choppy on Firefox. On Safari it's OK, but could be better. Similar TutorialsHi, I have a scenario in which i have to drag and drop some objects in a circular motion, but under spacific boundaries. To expain the scenario better, I have attached a image of the problem. If possible kindly provide me code, either logical description/solution of the problem would be very helpful. Thanks Sa9chit Hello everyone, I have written a color tween script based off of istallkizza's script that he provided for someone else in a different thread (http://codingforums.com/showpost.php...20&postcount=5.) It works, but the more it is used, the faster it runs, can anyone help me diagnose the problem? Code: var colorArr = new Array(); var colorSym = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]; var colorInt; for (i=0;i<colorSym.length;i++) { for (n=0;n<colorSym.length;n++) { colorArr.push(colorSym[i]+colorSym[n]); } } function colorTween(celem,r,g,b,time){ initColor = colorToHex(document.getElementById(celem).style.backgroundColor); origColor = splitColor(initColor); currColor = splitColor(initColor); targetColor = [colorArr[r], colorArr[g], colorArr[b]] colorIncs = [Math.round(diffBetween(origColor[0],targetColor[0])/time),Math.round(diffBetween(origColor[1],targetColor[1])/time),Math.round(diffBetween(origColor[2],targetColor[2])/time)]; startColorFade(); function stopInt() { if (colorInt) { clearInterval(colorInt); } } function startColorFade() { stopInt(); var colorInt = setInterval("this.colorFader()",time); } this.colorFader = function() { currColor[0] = colorArr[arrayIndex(colorArr,currColor[0]) + colorIncs[0]]; currColor[1] = colorArr[arrayIndex(colorArr,currColor[1]) + colorIncs[1]]; currColor[2] = colorArr[arrayIndex(colorArr,currColor[2]) + colorIncs[2]]; document.getElementById(celem).style.backgroundColor = "#"+currColor.join(""); if (Math.abs(diffBetween(currColor[0],targetColor[0])) <= Math.abs(colorIncs[0])) { currColor = splitColor("#"+targetColor.join("")); document.getElementById(celem).style.backgroundColor = "#"+targetColor.join(""); stopInt() } } function arrayIndex(arr,check){ for (var i=0;i<=arr.length;i++) { if (arr[i] === check) { return i; } } return false; } function diffBetween(c1,c2){ var num1 = arrayIndex(colorArr,c1); var num2 = arrayIndex(colorArr,c2); return num2-num1; } function splitColor(color){ return [color.substring(1,3),color.substring(3,5),color.substring(5,7)]; } function colorToHex(nhcolor) { if (nhcolor.substr(0, 1) === '#') { return nhcolor; } var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(nhcolor); var red = parseInt(digits[2]); var green = parseInt(digits[3]); var blue = parseInt(digits[4]); var rgb = blue | (green << 8) | (red << 16); return digits[1] + '#' + rgb.toString(16); } } The script can be viewed in action he http://www.webskethio.com/websites/index.php tween.js is a nice script that moves layers from one location to another. I have a hard time wrapping my head around it because as you all know, my skills are basic at best (I know enough to really screw things up). My problem is I have 3 layers and only one is visible at a time. When you click link one, any layer that is on the page moves down while the layer corresponding to the link moves up into place. My first thought was a sloppy function and repeat for each link: Code: function annomateT1() { Down1= new Tween(document.getElementById('text02').style,'top',Tween.regularEaseOut,85,580,2,'px'); Down1.start(); Down2 = new Tween(document.getElementById('text03').style,'top',Tween.regularEaseOut,85,580,2,'px'); Down2.start(); Up1 = new Tween(document.getElementById('text01').style,'top',Tween.bounceEaseOut,580,85,4,'px'); Up1.start(); } Then the link one would be just "javascript:"annomateT1()" The animation works, its just sloppy and doesn't work consistently (the second layer seems to get "stuck"). The tween class has some event handlers and listeners and I tried using them but those scripts didn't even work - I simply don't know enough. Here is a link to the tween.js page for those who are interested: http://jstween.blogspot.com/ Thanks in advance for your help... How do I use JS to make an html file that displays vehicular motion on intersecting roadways? - FULL QUESTION IS ENCASED IN SAMPLE HTML BELOW HERE Code: <style> .Road1 { background: black; color: white; width: 30px; height: 250px; border: solid black 2px; } .IntersectContainer { width: 100%; } .Road2a { background: darkred; color: white; float: left; margin-left: 20%; width: 30%; border: solid black 2px; } .Road2b { background: darkred; color: white; float: right; margin-right: 20%; width: 30%; border: solid black 2px; } pre { background: turquoise; color: black; width: 40%; font-weight: bold; padding: 1%; } </style> <body style="background: #349533;"> <center> <textarea rows=20 cols=70> How do I use JS to make an html file that displays vehicular motion on intersecting roadways? Since I do not know how to do this in JS, I include only html code that simulates the display. This appears to be impossible to do in JS; but JS easily moves images from left to right and up and down; so the solution to the problem seems to be to create a traffic grid with JS and then have images that look like vehicles move along the grid roadways. The kicker is this: the JS has to have a series of funx that allow the following: 1 add more vehicles to a part of the gridway to simulate the buildup of traffic on one road section 2 speed variances between vehicles: slow vehicles, fast vehicles, stationary vehicles 3 remove vehicles from a part of the gridway to simulate how traffic jamming can be reduced The creation of these 3 items would require a button-clicking action somewhere onscreen to do the job. Below here is html code that simulates one potential display of this gridway: </textarea> </center> <hr> <center> <div Class="Road1"> Road1 <br> motion <br> down <br> | <br> | <q style="background: darkred; color: white;" width: 15px;> car </q> </div> </center> <center> <div class="IntersectContainer"> <div class="Road2a"> Intersecting Road2 <br> motion left to right --------- <q style="background: #955479; color: black;" width: 15px;> car </q> </div> <div Class="Road2b"> Intersecting Road2 <br> motion left to right --------- <q style="background: #504504; color: black;" width: 15px;> car </q> </div> </div> </center> <cite style="background: white; color: darkblue; width: 50px; float: left; margin: 5px;"> button speed of cars on road 1 </cite> <cite style="background: white; color: darkblue; width: 50px; float: left; margin: 5px;"> button speed of cars on road 2 </cite> <cite style="background: darkblue; color: white; width: 50px; float: right; margin: 5px;"> button add cars to road 1 </cite> <cite style="background: darkblue; color: white; width: 50px; float: right; margin: 5px;"> button add cars to road 2 </cite> <center> <div Class="Road1"> Road1 <br> motion <br> down <br> | <br> | <q style="background: #434349; color: black;" width: 15px;> car </q> </div> </center> <center> <pre> TWO IMPORTANT POINTS: 1 Don't be seduced into using the html code shown here because it will only interfere with the solution 2 Since this is a difficult problem to solve any efficient solution should include some sort of copyright credit to the encoder </pre> </center> **just realised I have put this in the wrong section
Hi, I am new here, I am trying to find solution for one problem with my new web page, I want to use amazing effect -by mouse draging or swipe on the certain image which should launch animation effect (something like image rotating) -set of images should run dynamicaly and so simulate fluid effect (movie). For a better Idea what I need it can be for example something as physical lever switch with spring when this switch is slightly tilted spring complete this action and switch is flipped to other state. Or another example image of book should be on web and when someone drag and pull page this should independently continue and complete action - turn to new page. So my question .. is something like that possible with javascript if yes can You please point me where I have look or how this can be done, each advice will be valuable for me or maybe javascript isnt right choice for this can You advise me? THANKS I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? All, I have the following bit of CSS: Code: ul li{background:url(images/marker.jpg) top left no-repeat; background-position:0 3px; margin:0; padding-left:13px; } So basically on my page whenever there is a bullet it displays this marker. I put in the following code to make the bullet become clickable: Code: <li onclick="javascript:showdesc('This is info about bulk delivery', 'bulk');">Bulk Delivery</li><div id="bulk"></div> I then have the following javascript to handle that: Code: <script type="text/javascript"> function showdesc(desc, type){ if(type=="bulk"){ document.getElementById("bulk").innerHTML = desc; } } </script> Is there a way to incorporate CSS into the JS that will allow me to use a different image (down arrow) and make that clickable to then make the <div id="bulk"></div> not have the desc in it anymore? Thanks in advance! I have one jsp popup window. In that popup window i have 5 tabs. each tab have different functionality. the bottom of the popup window two button i have. one is "save" and another one is "save&close". By default 1st tab will showup in my popup window. When i click other tabs "save" and "save&Close" buttons will show up commonly. I recently implemented one logic if i do some modifications in this popup window with first tab after i click on "save" button one small popup window should open. which is working fine. my problem is : that popup should open only if i do modification under 1st tab. but the popup opens remaining tab modifications also when i do click on "save" button. How do i stop that popup if i do modifications in remaining tabs other than first tab ?? I'm very very new to coding. I need to make a very basic javascript game for school. I'm trying to modify this ball bouncing game, but the ball doesn't collide with the paddle. Where have I gone wrong? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>HoffHop!</title> <style> #playingArea{ position: absolute; top: 100; left: 100; border: 2px solid black; width: 500; height: 500; background-color: rgb(192,192,192); } #paddle{ position: absolute; top: 470; left: 228; width: 64; height: 16; } #ball{ position: absolute; top: 18; left: 200; width: 34; height: 34; } #score{ position: absolute; top: 486; left: 0; width: 500; height: 14; font-size: 10pt; color: white; background-color: rgb(32,128,64); } </style> <script language="JavaScript"> //get info, process data, update screen objects //instance vars var ball; var paddle; var score; //initial speeds var dx = 5; var dy = 5; var currentScore = 0; var timer; //set initial conditions for ball and paddle var paddleLeft = 228; var ballLeft = 300; var ballTop = 4; function init(){ //instantiate HTML object instance vars ball = document.getElementById('ball'); paddle = document.getElementById('paddle'); score = document.getElementById('score'); //register key listener with document object document.onkeydown = keyListener; //start the game loop start(); } function keyListener(e){ if(!e){ //for IE e = window.event; } if(e.keyCode==37 && paddleLeft > 0){ //keyCode 37 is left arrow paddleLeft -= 4; paddle.style.left = paddleLeft + 'px'; } if(e.keyCode==39 && paddleLeft < 436){ //keyCode 39 is right arrow paddleLeft += 4; paddle.style.left = paddleLeft + 'px'; } } function start(){ //game loop detectCollisions(); render(); difficulty(); //end conditions if(ballTop < 470){ //still in play - keep the loop going timer = setTimeout('start()',50); } else{ gameOver(); } } function detectCollisions(){ //just reflect the ball on a collision //a more robust engine could change trajectory of ball based //on where the ball hits the paddle if(collisionX()) dx = dx * -1; if(collisionY()) dy = dy * -1; } function collisionX(){ //check left and right boundaries if(ballLeft < 4 || ballLeft > 462) return true; return false; } function collisionY(){ //check if at top of playing area if(ballTop < 4) return true; //check to see if ball collided with paddle if(ballTop > 470){ if(ballLeft > paddleLeft && ballLeft < paddleLeft + 64) return true; } return false; } function render(){ moveBall(); updateScore(); } function moveBall(){ ballLeft += dx; ballTop += dy; ball.style.left = ballLeft; ball.style.top = ballTop; } function updateScore(){ currentScore += 5; score.innerHTML = 'Sco ' + currentScore; } function difficulty(){ //as the game progresses, increase magnitude of the vertical speed if(currentScore % 1000 == 0){ if(dy > 0) dy += 1; else dy -= 1; } } function gameOver(){ //end the game by clearing the timer, modifying the score label clearTimeout(timer); score.innerHTML += " Game Over"; score.style.backgroundColor = 'rgb(128,0,0)'; } </script> </head> <body onLoad="init()"> <h1>Bask-A-Bounce</h1> <div id="playingArea"> <div id="paddle"> <img src="paddle1.gif"> </div> <div id="ball"> <img src="ball.gif"> </div> <div id="score"> Sco 0 </div> </div> <embed name="Baywatch" src="Baywatch.mp3" loop="false" hidden="true" autostart="true"> </embed> </body> </html> |