JavaScript - Round Corners?
Hey Guys,
I'm working on a site and it needed borders with opacity, and since you can do it with CSS I done it With jQuery. But now I would like to round the corners of it, I did try border-radius, but it's only effecting the containing div not the borders(see below). Is there a solution to this? Here's the small snippet of JS: PHP Code: $('.mainContent').border({ width: 6, color: 'white', alpha: .4 }); Similar TutorialsJust started to learn java & came up with the following, but can't get the math.round to work. Anyone able to tell me where I'm going wrong please ??? <p> <script type="text/javascript">// <![CDATA[ var metrics = { "mm" : 1, "cm" : 10, "m" : 1000, "inch" : 25.4, "foot" : 304.8 }; function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes) } function roundme(len, wid, sq){ math.round.len; wid = math.round(wid); sq = math.round(sq); alert(len); }; function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.roundform.numberfield.value = parseFloat(newnumber); // Output the result to the form field (change for your purposes) }; function changeme(id, action) { var val = document.getElementById("sizegroup"); if (val.style.display == 'none') { val.style.display = 'block' } else { val.style.display = 'none' } }; function convert(num, dec){ var val = document.getElementById("boxa").value; var val2 = document.getElementById("boxb").value; if(isNaN(val)){return val}; if(isNaN(val2)){return val2}; document.getElementById("boxc").value = val * metrics[document.getElementById("choice1").value]/ metrics[document.getElementById("choice3").value]; metrics[document.getElementById("choice1").value]/ metrics[document.getElementById("choice3").value]; document.getElementById("boxd").value = val2 * metrics[document.getElementById("choice2").value]/ metrics[document.getElementById("choice4").value]; document.getElementById("sqmtrs").value = document.getElementById("boxc").value * document.getElementById("boxd").value ; document.getElementById("boxc").value = math.round(document.getElementById("boxc").value); }; var interval = null; function watchChanges(){ interval == null ? setInterval("convert()", 500) : clearInterval(interval); } // ]]></script> </p> <p>Length in imperial-metric / Width in imperial-metric</p> <div><input id="boxa" style="width: 40px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="choice1" onchange="convert();"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">metres</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select> <input id="boxb" style="width: 40px;" onfocus="watchChanges()" onblur="watchChanges()" type="text" /><select id="choice2" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option value="m">metres</option> <option selected="selected" value="foot">feet</option> <option value="inch">inches</option> </select></div> <div><input id="boxc" style="width: 40px;" type="text" disabled="disabled" /><select id="choice3" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option selected="selected" value="m">metres</option> <option value="foot">feet</option> <option value="inch">inches</option> </select> <input id="boxd" style="width: 40px;" type="text" disabled="disabled" /><select id="choice4" onchange="convert()"> <option value="mm">millimeters</option> <option value="cm">centimeters</option> <option selected="selected" value="m">metres</option> <option value="foot">feet</option> <option value="inch">inches</option> </select></div> <p> </p> <div>Total sq metres : <input id="sqmtrs" style="width: 40px;" type="text" value="" disabled="disabled" /></div> <p> </p> <div class="label">Please round up to half a metre when choosing</div> <table border="0" cellspacing="0" cellpadding="5"> <tbody> <tr> <td>Round:</td> <td><input type="text" name="numberfield" value="" /> to <input type="text" name="decimalfield" value="2" size="3" /> decimal places</td> </tr> <tr> <td>Result:</td> <td><input type="text" name="roundedfield" value="" /> <input onclick="roundNumber(numberfield.value, decimalfield.value);" type="button" value="Calculate" /></td> </tr> </tbody> </table> i had to create a function to calculate percentage and round to integer need 2 parameters of item and sum function will return value of item variable divide the sum by 100 and round to nearest integer using Math.round this is my code that i came up with Code: function calcPercent(item,sum){ // script element to calculate the percentage which is rounded to the nearest integer var items = Math.round( (item/sum)*100); // script element to get the percentage return items; } calcPercent(1, 3); Does this make sense? thanks Hi, First time user of Javascript and built an online calculator, trouble is I dont know where or how to code it so the answer ends with only 2 decimals I have embedded code, help appreciated. Personally I think it's a miracle the darn thing works. Link to page it's on. Any help appreciated, I have searched and read but after hours of trying stuff gave up. <!-- function treevalue() { document.volume.result.value=(((3.14159*((document.volume.radius.value)*(document.volume.radius.valu e)))*(document.volume.height.value))/3)*(document.volume.base.value)*(document.volume.e.value)*(document.volume.fv.value)*(document.volum e.l.value); } // --> Thanks Eric Hello: I have this js function: Code: <script type="text/javascript"> function updatesum() { document.PaymentForm.newbalance.value = (document.PaymentForm.balance.value -0) - (document.PaymentForm.paymentamount.value -0); } </script> I want to round the value of Code: document.PaymentForm.newbalance.value to two decimal points. May I request some assistance! Having trouble with the alert(Math.round coding. "r" is the results or final value, and I want to divide this result/final value by "f" I have alert(Math.round(r / f) + ' calories/day to burn); but I its coming up saying NaN calories/day to burn. How do I divide "f" into "r" correctly? Code: } function calculate() { var f = document.forms[0], g, w, f, h, a, l, r; for (var i=0; i<(f.length-1); i++) { if (f.elements[i].selectedIndex == 0) { alert('Sorry, all options must be selected.'); return false; } } g = f.g.options[f.g.selectedIndex].value; w = f.w.options[f.w.selectedIndex].value; h = f.h.options[f.h.selectedIndex].value; a = f.a.options[f.a.selectedIndex].value; l = f.l.options[f.l.selectedIndex].value; if (g == 'm') { r = ((66 + ((13.7 * w) / 2.2) + (5 * h * 2.54)) - (6.8 * a)) * l; } else { r = ((655 + ((9.6 * w) / 2.2) + (1.8 * h * 2.54)) - (4.7 * a)) * l; } alert(Math.round(r) + ' calories/day is what you require'); alert(Math.round(r / f) + ' calories/day to burn); return false; i have a program where a user enters a temperature in farenheit and the program converts it to celcius. below is my code: Code: <html> <head> <title>JavaScript Assignment 4 Part 1</title> </head> <body> <h2>Welcome to the Temperature Calculator!!</h2> <script type="text/javascript"> var fTemp; var number1; var cTemp; fTemp = window.prompt( "Please enter temperature in Farenheit:", "0" ); number1 = parseInt( fTemp ); cTemp = (5/9) * (number1 - 32); document.writeln("The corresponding temperature in Celcius is: " + cTemp); </script> </body> </html> what i cant figure out is how to round off the temperature in celcius so that it doesnt display something like 26.666666666667 i tried putting math.round in "cTemp = (5/9) * (number1 - 32);" but when i do my program doesnt work any advice on how to go about doing this? thanks Hi, my javascript calculates a total figure. It rounds it up though and I want it to give me a decimal (x2) total. Please help. Here is my code so far: Code: <script type="text/javascript"> function calculateText() { var op1=document.getElementById('Age02'); var op2=document.getElementById('Girl35'); var op3=document.getElementById('Boy35'); var op4=document.getElementById('Girl610'); var op5=document.getElementById('Boy610'); var op6=document.getElementById('Age11'); var op7=document.getElementById('Guest'); var op8=document.getElementById('VIP'); var op9=document.getElementById('School'); var op10=document.getElementById('3DFilm'); var op11=document.getElementById('BFast'); var op12=document.getElementById('PNGift'); var op13=document.getElementById('PStand'); var op14=document.getElementById('PLrg'); var op15=document.getElementById('PReP'); var op16=document.getElementById('KyMg'); var op17=document.getElementById('SnwGlb'); var op18=document.getElementById('PBbl'); var op19=document.getElementById('USB'); var op20=document.getElementById('SantaL'); var op21=document.getElementById('SantaK'); var op22=document.getElementById('FreeP'); var op23=document.getElementById('PUpgrd'); var op24=document.getElementById('StaffP'); var op25=document.getElementById('CompEntry'); var op26=document.getElementById('241'); var op27=document.getElementById('50Percent'); var op28=document.getElementById('Voucher'); var result=document.getElementById('Total'); if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0; if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0; if(op3.value=="" || op3.value!=parseFloat(op3.value)) op3.value=0; if(op4.value=="" || op4.value!=parseFloat(op4.value)) op4.value=0; if(op5.value=="" || op5.value!=parseFloat(op5.value)) op5.value=0; if(op6.value=="" || op6.value!=parseFloat(op6.value)) op6.value=0; if(op7.value=="" || op7.value!=parseFloat(op7.value)) op7.value=0; if(op8.value=="" || op8.value!=parseFloat(op8.value)) op8.value=0; if(op9.value=="" || op9.value!=parseFloat(op9.value)) op9.value=0; if(op10.value=="" || op10.value!=parseFloat(op10.value)) op10.value=0; if(op11.value=="" || op11.value!=parseFloat(op11.value)) op11.value=0; if(op12.value=="" || op12.value!=parseFloat(op12.value)) op12.value=0; if(op13.value=="" || op13.value!=parseFloat(op13.value)) op13.value=0; if(op14.value=="" || op14.value!=parseFloat(op14.value)) op14.value=0; if(op15.value=="" || op15.value!=parseFloat(op15.value)) op15.value=0; if(op16.value=="" || op16.value!=parseFloat(op16.value)) op16.value=0; if(op17.value=="" || op17.value!=parseFloat(op17.value)) op17.value=0; if(op18.value=="" || op18.value!=parseFloat(op18.value)) op18.value=0; if(op19.value=="" || op19.value!=parseFloat(op19.value)) op19.value=0; if(op20.value=="" || op20.value!=parseFloat(op20.value)) op20.value=0; if(op21.value=="" || op21.value!=parseFloat(op21.value)) op21.value=0; if(op22.value=="" || op22.value!=parseFloat(op22.value)) op22.value=0; if(op23.value=="" || op23.value!=parseFloat(op23.value)) op23.value=0; if(op24.value=="" || op24.value!=parseFloat(op24.value)) op24.value=0; if(op25.value=="" || op25.value!=parseFloat(op25.value)) op25.value=0; if(op26.value=="" || op26.value!=parseFloat(op26.value)) op26.value=0; if(op27.value=="" || op27.value!=parseFloat(op27.value)) op27.value=0; if(op28.value=="" || op28.value!=parseFloat(op28.value)) op28.value=0; result.value=0; result.value=parseInt(result.value); result.value=parseInt(result.value)+parseInt(op1.value*5)+parseInt(op2.value*5)+parseInt(op3.value*5)+parseInt(op4.value*5)+parseInt(op5.value*5)+parseInt(op6.value*5)+parseInt(op7.value*0)+parseInt(op8.value*8.50)+parseInt(op9.value*3.75)+parseInt(op10.value*0)+parseInt(op11.value*10)+parseInt(op12.value*5)+parseInt(op13.value*3)+parseInt(op14.value*4)+parseInt(op15.value*2)+parseInt(op16.value*4)+parseInt(op17.value*5)+parseInt(op18.value*3)+parseInt(op19.value*5)+parseInt(op20.value*4)+parseInt(op21.value*3)+parseInt(op22.value*0)+parseInt(op23.value*1)+parseInt(op24.value*0)+parseInt(op25.value*0)+parseInt(op26.value*4)+parseInt(op27.value*2)-parseInt(op28.value); } </script> I was wondering if there is a way to find the total round trip time of a request. Addins like firebug and chromes console show you this round trip time but i was hoping there was a way to extract it from the response itself. I would also like to know the response time from when the server sent the request and the client received it. I do not think this is possible since the server and client have different timing systems but it would be very useful. I am using curvy corners, and it is working fine, as long as I only want one rounded box... I want (at least) two, and I am having trouble adding a second <div id> to the script. I'm not able to decipher much of javascript, and the explanation that came with the code isn't clear enough for me. Can anyone help? Here's the code... Code: <script type="text/JavaScript"> window.onload = function() { var settings = { tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true } var divObj1 = document.getElementById("container"); var divObj2 = document.getElementById("login"); curvyCorners(settings, divObj1, divObj2); } </script> <title>Untitled Document</title> </head> <body> <div id="container"> <div id="login"> <img src="images/fcbdivcmyk_small.png" /><br /><br /> BLAH BLAH BLAH </div> <!-- This is the end of #login --> <div id="banner"> This is the text to the right. </div> <!-- This is the end of #banner --> </div> <!-- This is the end of #container --> Surprisingly, this jQuery plugin nearly works in IE6. You can see the error that is produced at the bottom of the article corner. (I'm tackling the other issues... .png later) link: http://www.happydogwebproductions.com/nerdery/ Any clue on how to fix this? Hi everyone, I've downloaded the curvy corners codes from the following address: http://www.curvycorners.net/downloads/ The instructions in the curvycorners.src.js file say that all i need to do is add the following piece of code which I've inserted into the head section: <script type="text/javaScript" src="js/curvycorners.src.js"></script> <style type="text/css"> <!-- p.round { -webkit-border-radius: 25px; -moz-border-radius: 25px; CCborderRadius: 25px; } --> </style> However, it's not rendering in opera and internet explorer. I wondered if someone could tell me where I'm going wrong? The is the xhtml I'm targeting: Code: <div id="content_wrapper"> <div class="accomm"> <h3 id="accomm"><a href="#" title="Quality accommodation"> Quality accommodation</a></h3> <p class="round">lam et deliciisqui cor resto il eos verciderit ee litate niam eaqui denihicae dolorio rpore, nisinim aut as eum alitior eriaesti atioreiunde erem is sin expelenet, verae dus, conseribus dit odit remqui volestias exceri ullam, con cullatiamet, ut ipite officil igenem non. <a href="about.php">Learn more...</a></p> <p id="fees"><a href="fees.php">Fee structure</a></p> </div> <div class="local"> <h3 id="local_area"><a href="#" title="Our local area"> Our local area</a></h3> <p class="round">lam et deliciisqui cor resto il eos verciderit ee litate niam eaqui denihicae dolorio rpore, nisinim aut as eum alitior eriaesti atioreiunde erem is sin expelenet, verae dus, conseribus dit odit remqui volestias exceri ullam, con cullatiamet, ut ipite officil igenem non. <a href="local_area.php">Learn more...</a></p> <p id="directory"><a href="directory.php">Hospital directory</a></p> </div> <div class="welcome"> <h3 id="packages"><a href="#" title="Welcome packages">Welcome packages</a></h3> <p class="round">lam et deliciisqui cor resto il eos verciderit ee litate niam eaqui denihicae dolorio rpore, nisinim aut as eum alitior eriaesti atioreiunde erem is sin expelenet, verae dus, conseribus dit odit remqui volestias exceri ullam, con cullatiamet, ut ipite officil igenem non. <a href="welcome_packs.php">Learn more...</a></p> <p id="map"><a href="location_map.php">Find us on the map</a></p> </div> </div> </div> Really appreciate any help. |