JavaScript - Does Order Of Logic Comparisons Affect Speed In The Same Statment?
was wondering if it made sense to optimize the comparison order inside an if() statement if one of the comparison targets is a function call eg:
Code: var a = true, b = function() {return false;}; if (b() || a) {...} if (a || b()) {...} would the second statement run faster because it would theoretically never need to call b() in this situation? can the eval order be relied on? does this depend on the js engine/internal optimizations? thanks, Leon Similar TutorialsCould anyone tell me (or link me to some place that can) why the following if-statement will execute? if (5!=6 || 7!=8) { alert("Why does this work?"); } Thanks I am creating a website. I am working on the products page first. Please go here to see the site... http://www.fingerguitar.com You see those social network icons under the product description div? When the mouse rolls over the right edge I want a drawer affect that pulls the icons into view and lets the user click one of the social links. When the user rolls his mouse away from the section, the drawer should return to its position. Any help... leads or anything would be awesome and much appreciated! Hi guys, I have a form I am working on that has 4 text boxes in it, but I want to change it so that if a Radio button is selected it makes the 4th text box disappear, but still gives it a value of "0" when the form is submitted. Is this possible with Javascript? Here is what it looks like so far - Code: <FORM><table id='table_columns'> <tr> <td colspan="2" align="center">3 Columns <input name="3columns" type="radio" value="3columns"> 4 Columns <input name="4columns" type="radio" value="3columns"></td></tr><tr> <td align="right"><p>Column 1</p></td> <td align="left"><input class="txt" size="2" maxlength="2" name="WIDTH1" size="20" Title="Insert the desired width" value="25" /></td> </tr> <tr> <td align="right"><p>Column 2</p></td> <td align="left"><input class="txt" size="2" maxlength="2" name="WIDTH2" size="20" Title="Insert the desired width" value="25" /></td> </tr> <tr> <td align="right"><p>Column 3</p></td> <td align="left"><input class="txt" size="2" maxlength="2" name="WIDTH3" size="20" Title="Insert the desired width" value="25" /></td> </tr> <tr> <td align="right"><p>Column 4</p></td> <td align="left"><input class="txt" size="2" maxlength="2" name="WIDTH4" size="20" Title="Insert the desired width" value="25" /></td> </tr> </table> <br /> <input type="button" value="Save" Title="Save these Settings" onClick="updateSettings('COLUMNS');" /></FORM> If 3 Columns, WIDTH4 is not viewed and defaults to "0". If 4 Columns, all are visible and the number is then optional. Would love some assistance with this as my coding skills are pretty limited and my fingers have gone numb trying to google an answer. I want the output to be this way Student: Doe, John eMail: jd@email.com Course ID: COIN-O70A.01 ----------------------- Can any one pls help me with the display. If I use alert instead of return then I works. But I need to display it in the document. Code: <html> <head> <title>Variable - Examples 1</title> <script type="text/javascript"> function Student(firstName, lastName, email,courseID){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.courseID = courseID; } Student.prototype = { constructor : Student, toString : studentInfo }; function studentInfo(){ return this.firstName + "," + this.lastName + '\n'+ this.email + '\n' + this.courseID; } var student = new Student("Doe", "John", "Doeohn@gmail.com","COIN 70A.01"); </script> </head> <body> <script type="text/javascript"> document.writeln(student.toString()); </script> </body> </html> Code: var areas = { "The Plains of CASCADIAN": { yMin: 0, yMax: 20, xMin: 0, xMax: 24 }, "The Forests of BELGROS": { yMin: 0, yMax: 34, xMin: 24, xMax:50 }, "Bewitched VOLRAP": { yMin: 0, yMax: 42, xMin: 50, xMax:100 }, "The Moutains of MELDROSS": { yMin: 26, yMax: 52, xMin: 0, xMax: 48 }, "The Moutains of OLAP": { yMin: 49, yMax: 68, xMin: 0, xMax: 48 }, "The Swamps of NEMBRESS": { yMin: 54, yMax: 90, xMin: 44, xMax: 100 }, "The Great Wood of OLKLEMPT": { yMin: 62, yMax: 100, xMin: 32, xMax: 100 }, "Dark Forests of MURLAP": { yMin: 60, yMax: 100, xMin: 0, xMax: 42 }, "Imperial MANTRIOCK": { yMin: 22, yMax: 58, xMin: 44, xMax:100 } } How would you reffer to the areas with a javascript if statment or case? How do you format a if statment for a multidemensional array.
This code is not working correctly when you type get_data it should only work if you already have typed load_hacker. But get_data works withought load_hacker.
Code: <script type="text/javascript"> function command(){ if(command.value = "load_hacker" && level.value == 1){ document.getElementById("command").value = ""; document.getElementById("number").value = ""; plus(); } else { document.getElementById("command").value = "..."; document.getElementById("number").value = "..."; } if(command.value = "get_data" && level.value == 2){ document.getElementById("command").value = ""; document.getElementById("number").value = ""; plus(); } else { document.getElementById("number").value = "..."; document.getElementById("command").value = "..."; } } </script> <script type="text/javascript"> function plus(){ document.getElementById("level").value ++; } </script> ><input type="text" value="" id="command" size="" style="background-color:transparent;border:0px solid white;" /> #<input type="text" value="" id="number" size="10" style="background-color:transparent;border:0px solid white;" /> <input type="button" value="Enter" onclick="command()" /> <input type="hidden" value= 1 id="level" /> Hello. I have a problem. I use google map to show some points. I have to show all points for some region, and number of points gets to 4.000. So it takes some minutes to show all points. I use gif image-> size: 400 bytes I found http://fundrace.huffingtonpost.com/ and it takes only couple of seconds to load more 1000 markes. Does someone know how to resolve this? Thanks Hello, I'm working on a rotator and I'm needing to slow it down. I think I would use var speed right? How would I use it in this script? <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.slideshow').cycle({ fx: 'fade' }); }); </script> Hi all, I'm justing wondering about the behavior of JS in regards to adding elements, suppose I have something like this Code: <div id="myDiv"></div> ... function test() { for (i=0 i<100; i++) { var obj = document.create("div"); // do stuff to style div and set content document.getElementById("myDiv").appendChild(obj); } // DO SOMETHING WITH ONE OF THESE DIVS } I'm just wondering at the point I hit that "// DO SOMETHING WITH ONE OF THESE DIVS", are all the divs I have added in the DOM available to access? I ask because I have some code at work in which a tester is reporting an error that happens which I can't reproduce, and they and others have had it a few times. The only way I can explain it in my mind is if the div is not available to me at the time of execution. So I'm just looking to rule it out or confirm my hunch. Is document.getElementById("myDiv").appendChild(obj); synchronous and the next line of code wont execute until the DOM is ready or is it in fact a asynchronous call and therefore adding alot of elements to the DOM could result in a lag so some divs or not available straight away. Any information much appreciated, I hope I have been clear enough. I'm using IE7 and so are the testers. Thanks, Dale I have this horizontal news ticker which works just perfect in ie7 regarding to speed, but when looking at the same page in ie8 the speed is very slow... Has anybody else encountered this, and if yes... How do I solve this? Code: initialize: function(element, options) { this.setOptions({ marHeight: 18, marWidth: 565, steps: 20, speed: 20, direction: 'left', pauseOnOver: true, pauseOnContainerOver: true }, options); this.timer = null; this.textElement = null; this.mooqueeElement = element; this.constructMooquee(); } Thanks in advance :-) 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> In the home page (index.html) i have a flash intro. The first time a user sees the website, the intro should play. Once he goes to another page (about_us or contact_us) and comes back to the home page, it should show a different swf (the version without the intro) - i have created two swf files. I need to know how to change them when the user has already seen the intro or was in the home page before. When i googled, i found something on cookies. I have no clue on how to set them and change the swf file. Would be great if someone has already done this or point me to a tutorial. i need java script. please help!!!!!!! I have made myself an HTML Menu which is located on top of my current Flash object. I have a question whether it really is not possible to get the same effect as 'text' has on the original "Flash Menu" EX: www.moebelarkitekten.dk and get the same effect over at my new HTML menu (Coded with Jquery) EX: http://www.richyjassal.co.uk/moebelar/ Right now it is almost the same effect, but only: OnMouseOver align text to Right OnMouseOut text to align left A guide, or other? i have pasted below java script code. please check write or wrong <script language = "JavaScript" type="text/javascript"> // Remove down to "ConnectionSpeed Detection section" if you don't want to use cookies // If you drop a cookie it can be picked up on return by php or something else function setCookie(name, value, expire) { document.cookie = name + "=" + escape(value) + ((expire == null ? "" : (";expires=" + expire.toGMTString()))); // alert('A cookie called '+name+' is now set with value: '+value); //enable to alert user of cookie } function getExpireDate() { var expires = new Date(); expires.setTime((new Date().getTime() + 1000 * 60 * 60 * 24 * 365)); return expires; } // ConnectionSpeed Detection section var datasize = 31468; // Size of data being transferred, in Bytes var startTime = 0; var endTime = 0; var date = 0; var ctype = ""; var textMessage = ""; function calcThroughput() { var diffTimeMilliseconds = endTime - startTime; var diffTimeSeconds = diffTimeMilliseconds / 1000; var bits = (datasize * 8); // convert Bytes to bits, var kbits = bits / 1024; // convert bits to kbits var throughput1 = kbits / (diffTimeSeconds * 100 / 100); throughput = throughput1 * .93; // account for IP packet header overhead - averages about 7% setCookie("MediaThroughput", throughput, getExpireDate()); // Remove to not use cookie if (throughput < 185) { ctype = "Home.aspx"; } if (throughput > 185) { ctype = "intro.aspx"; } textMessage = "Bandwidth: <B>" + ctype + "</B><br>time to load: (sec): <B>" + diffTimeSeconds + "</B><BR>kbits loaded:<B> " + kbits + "</B><BR>Throughput (kbps): <B>" + throughput + "</B>" document.location = ctype; } </script> <script language = "Javascript" type="text/javascript"> <!-- A bunch of binary data here in the actual file --> </script> </head><body> <script language = "Javascript" type="text/javascript"> date = new Date(); endTime = date.getTime(); calcThroughput(); </script> automatic detect default page and check to low band version go to html page or high band version go to flash page. please help!!!!!!!!!!!!!!!!!!!!!!!!! i need script will detect connection speed and redirect to a page:
Hello Experts, I did a website & I am having trouble wit it. In IE8, FF& Chrome, the site works perfectly. But in IE7, the site slows down very much that even the link hover effect doesn't show properly. I believe its some kind of javascript or Ajax request which is causing such delay. Can you guys please help me sort this out.... Here is the site with functionality... http://tinyurl.com/3qkunvy Here is the site without functionality but just the gallery is integrated... http://tinyurl.com/439ejhk The speed was even better before the Ajax is applied for contents. Any solutions/fixes please... Hello good coders! Thanks to the wonderful script provided by coothead he http://www.codingforums.com/showthread.php?t=87036 I was wondering how I could adjust the transition/fade speed between the images in the script? I tried a couple of different ways, but I couldn't get it working. Does anyone know how I can adjust this in a cross-browser compatible way? 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>multiple image maps</title> <base href="http://coothead.homestead.com/files/"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> /*<![CDATA[*/ #mapImage_holder { text-align:center; } #mapImage { border:1px solid #000; } /*//]]>*/ </style> <script type="text/javascript"> //<![CDATA[ var maps=new Array(); maps[0]='dots.gif,#dots'; maps[1]='map.jpg,#blood'; maps[2]='apple0.jpg,#apples'; var c=0; var speed=1000*10; //set for 10 secs, change to suit needs. function swapMap() { obj=document.getElementById('mapImage'); if(c==maps.length) { c=0; } obj.src=maps[c].split(',')[0]; obj.useMap=maps[c].split(',')[1]; c++; setTimeout('swapMap()',speed); } window.onload=swapMap; //]]> </script> </head> <body> <div id="mapImage_holder"> <img id="mapImage" src="dots.gif" alt="" usemap="#dots"/> </div> <div> <map id="dots" name="dots"> <area coords="85,40,110,65" href="http://www.bbc.co.uk" alt="" /> <area coords="225,100,250,125" href="http://www.itv.com/" alt=""/> <area coords="345,140,370,165" href="http://www.channel4.com/" alt=""/> <area coords="405,270,430,295" href="http://www.guardian.co.uk/" alt=""/> <area coords="35,290,60,315" href="http://www.independent.co.uk/" alt=""/> <area coords="605,460,630,485" href="http://www.thesun.co.uk/" alt=""/> </map> <map id="blood" name="blood"> <area coords="40,144,80,171" href="http://www.codingforums.com/" alt="" /> <area coords="112,144,152,171" href="http://www.w3schools.com/" alt="" /> <area coords="184,144,224,171" href="http://w3c.org/" alt="" /> <area coords="256,144,296,171" href="http://www.alistapart.com/" alt=""/> </map> <map id="apples" name="apples"> <area coords="0,0,116,146" href="http://www.axialis.com/" alt=""/> <area coords="124,0,236,146" href="http://www.photoshopsupport.com/" alt=""/> <area coords="244,0,360,146" href="http://www.photoshopuser.com/" alt=""/> <area coords="0,154,116,280" href="http://www.planetphotoshop.com/" alt=""/> <area coords="124,154,236,280" href="http://www.photoshopcafe.com/" alt=""/> <area coords="244,154,360,280" href="http://www.mozilla.com/" alt=""/> </map> </div> </body> </html> I was going through LinkedIn today, when I noticed something that I couldn't figure out, logic-wise. When you search using their search feature at top left, results come up live... no big deal, easy enough, keyup, no biggie. When you click outside the input box, it disappears, which is blur. However, if you click out of the input onto the search results, it remains, and stays up until you click somewhere outside of the input box or the search results. This I have no idea how is done. Is there a way to know what element a user clicks on? Anyone have thoughts/guidance for this? I'm using jQuery as a framework if that helps? |