JavaScript - Dynamic Font Resizing In Menu Bar
Hi Guys,
I have a multi language cms site and need to be able to resize font to fit the div its contained in so eg if I have a 300px wide navbar with 13px text: home | about | contact | services | products and in Russian its: fgfgdg |gghgfdhggghgfhgfh | gfg |gfdgfgdfgfdgffd dgfdgdg | gdfgfgdfgfgdfg I would like the font size to reduce down to fit the 300px fixed width div from say 13px to 10px or whatever fits. so it would be like: fgfgdg |gghgfdhggghgfhgfh | gfg |gfdgfgdfgfdgffd dgfdgdg | gdfgfgdfgfgdfg I was looking at http://jsfiddle.net/e8B9j/2/show/ and was hoping someone could get it to work to suit the above. So as above u'd have say 5 menu item divs nested in a navbar div Code: <div id="navbar"> <div class="menuItem">item</div> <div class="menuItem">item</div> <div class="menuItem">item</div> <div class="menuItem">item</div> <div class="menuItem">item</div> </div> ...or using ul and li's Any help greatly appreciated. Perhaps a jquery solution out there? Thanks Similar TutorialsI am trying to dynamically resize an image. Here is my code: Code: <img border="0" src="images/right.gif" width="16" height="100" name="right"> <SCRIPT Language=Javascript> <!-- function ChangeImgSize(){ right.height = 3000; } ChangeImgSize() //--> </SCRIPT> This is on an asp page, and the <script> tag is the last thing on the page before </body> The image does not get resized. I've been testing the page on current browsers (IE 8, Firefox, Chrome). I'm certain I'm doing something newbish, I don't really know Javascript all that well. Thanks in advance, Skip Hi I have two drop down menus I want the first one has name of the folders and when change the other dropdown has names of the sub-folders of this folder i have the top folders at the first dropdown how can i have the subfolders at the second when change first? the problem is how to open folder if i have folders aaaaa has subfolders(1111,2222,2233) bbbbb has subfolders(3333,4422,2433) ccccc has subfolders(1131,2232,2532) and each folder has subfolders how can i have name of these subfolders when change the topfolders(aaaaa, bbbbb, ccccc) I have more than 1000 top folders and eachone have 10 subfolders already i have all topfolders at first dropdown ,i want to have subfolders at second automatic , any help?? Hi, I have 3 selects in a form for day, month and year for the user to enter his/her birthday. What I'm looking for is a piece of code / script which will dynamically change the day dropdown menu dependent on the month which is selected to display the correct number of days, and also according to if it is a leap year. Ive tried looking on google but I'm not sure what the correct term is to look for? Could anyone please help? Thanks I have been searching everywhere and have found a few of articles available regarding dropdown menu.. couldnt get exactly what i wanted.. i am not really good at javascript, or even programing..am trying my best. anyway~ Here is what i want. something simple if there is more than 1 data entity (count>1) (Case 1), then execute 'select(drop down)' else (count <=1)(Case 2), then just show the data entity itself. (i dun even want the dropdown box to appear) as below screenshot or the attachment I have a script getting me the dropdown menu as below, i wanna modify this but not sure where to start... -------------------------------- <div id="abcdefg"> <form id="setLanguage" action="{$request_uri}" method="post"> <select name="selectlanguage" id="selectlanguage" onchange="setLanguage(this.value)"> {foreach from=$languages key=k item=language name="languages"} <option value="{$language.id_lang}" {if $language.iso_code == $lang_iso} selected {/if} >{$language.name} </option> {/foreach} </select> <input type="hidden" name="id_lang" id="id_lang" value=""/> </form> </div> -------------------------------- Really appreciate your help with modifying this. Please try not to give me a totally new script (i bet it will/may work better but i wouldnt be able to understand..:-( so no point...) Hello all! I hope everyone had a great Holiday I'm hoping someone can help me with a Switch Menu code. I borrowed and modded the code offered he http://www.dynamicdrive.com/dynamici...switchmenu.htm The site I'm trying to implement this menu on is: http://hardlyrhetoric.com/ste/projects.html Additional required files for this page a http://hardlyrhetoric.com/ste/tabcontent.js http://hardlyrhetoric.com/ste/tabcontent.css As you can see, the menu on the left will expand and collapse, revealing the sub-links perfectly fine. It will even display the content for each link in the first set of "Datacenters and Emergency Power" links, as it should. The problem is with each section after "Datacenters and Emergency Power" None of the links will display content in the right column the way the first set of links does. I've looked over the code for several hours... am I missing something basic??? Well i want to implement something very similar to this (youtube). My javascript knowledges are low. I think it has something to be with onload and onclick events with links. Do i have to write a function and include it on the html page? Where do i have to put the diferent contents? I would prefer to separate html content and javascript since i have some variable to display from my template engine like {$name}, {$uploaded_date}, etc. Thanks in advance Ok, I seem to be stuck on one part of my code. A quick background, this is a website to showcase various photography services. First, I will lay out what I have: The Javascript for my menu (in the head section): Code: <script type="text/javascript"> <!-- var timeout = 200; var closetimer = 1; var items = 0; function dropit(id) { canclcls(); if(items) items.style.visibility = 'hidden'; items = document.getElementById(id); items.style.visibility = 'visible'; } function mclose() { if(items) items.style.visibility = 'hidden'; } function mcls() { closetimer = window.setTimeout(mclose, timeout); } function canclcls() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null; } } document.onclick = mclose; // --> </script> Now, here is what I have in the body section Code: <div id="menu"> <ul id="control"> <li><a href="#" onmouseover="dropit('dropone')" onmouseout="mcls()">Wedding Portfolio</a> <div id="dropone" onmouseover="canclcls()" onmouseout="mcls()"> <a href="jamaicawed.html">Wedding in Jamaica</a> <a href="indianwed.html">Indian Wedding</a> </div> </li> <li><a href="#" onmouseover="dropit('m2')" onmouseout="mcls()">Model Portfolio</a> <div id="m2" onmouseover="canclcls()" onmouseout="mcls()"> <a href="emilymodel.html">Emily</a> <a href="nicolemodel.html">Nicole</a> </div> </li> <li><a href="#" onmouseover="dropit('m3')" onmouseout="mcls()">Other Works</a> <div id="m3" onmouseover="canclcls()" onmouseout="mcls()"> <a href="catalog.html">Catalog</a> <a href="#" onclick "alert">Boudoir</a> <a href="product.html">Product</a> </div> </li> <li><a href="#" onmouseover="dropit('m4')" onmouseout="mcls()">More</a> <div id="m4" onmouseover="canclcls()" onmouseout="mcls()"> <a href="aboutus.html">About Us</a> <a href="contact.html">Contact Us</a> </div> </li> </ul> </div> Ok, so the only thing I can't figure out how to do is create an onclick event for one of the menu items (boudoir) that confirms that the user is comfortable being exposed to a specific (topless) type of image. Would someone be kind enough to help? Hi Chaps, I have a dynamic list menu: PHP Code: <?php $currentCat = ''; $first = true ;?> <ul> <?php do { if ($currentCat != $row_rsCategory['catname']) { if (!$first) { echo "\n</ul>\n</li>\n"; } $currentCat = $row_rsCategory['catname']; ?> <li><?php echo $row_rsCategory['catname']; ?> <ul> <?php }?> <li><?php echo $row_rsCategory['galleryname']; ?></li> <?php $first = false; } while ($row_rsCategory = mysql_fetch_assoc($rsCategory)); ?> </ul> </li> </ul> I've tried looking for a show/hide script, to toggle category names/gallery names, but could only find ones that have static menu options, and have failed to edit existing code to fit....any help or guidence would be appreciated! Hi All, i know how to create a dynamic form or DIv ..but what i do not know is how to create a dynamic form/ or div into a previous dynamic one.. i need basically to see 5 dynamic forms / DIV in cascade where each one trigger the one coming after.. For what i need that : i have my user inserting information on the level 1. let say Copagny info 2- then he will be asked if he wants to add a sub level information ( subform) for that compagny or even many subforms at the same level .. and so on... 3- those sub level ( subforms ) can also call their respective subforms.. Any idea how to design this ? thanks I have made a script where you can add extra fields, and next to the row is a span that automatically displays the outcome from a calculation of three fields in that row. i.e. Q x (B - A) = total. Here is the bit that does the calculation: Code: function advCalc(selected) { var result = Number(document.formmain.elements["quantity"+selected].value) * (Number(document.formmain.elements["provideamount"+selected].value) - Number(document.formmain.elements["supplyamount"+selected].value)) ; result = result.toFixed(2) ; result = addCommas(result) ; document.getElementById("total"+selected).innerHTML = result ; } The bit that adds a new row of fields is: Code: function addPart(divName){ var newdiv = document.createElement('div') ; newdiv.setAttribute('id', 'partrow' + counter) ; newdiv.setAttribute('style', 'clear:both;') ; newdiv.innerHTML = "<div style='float:left;width:40px;text-align:center;margin:5px 5px 0px 0px;'>\r<input onkeyup=\"advCalc('" + counter + "')\" id=' quantity " + counter + "' type='text' value='1' size='1'/>\r</div>\r<div style='float:left;width:100px;text-align:left;margin:5px 0px 0px 0px;'>\r<input id='manufacturer" + counter + "'type='text' value='' size='9'/>\r</div>\r<div style='float:left;width:95px;text-align:left;margin:5px 5px 0px 0px;'>\r<input id='partnumber" + counter + "'type='text' value='' size='9'/>\r</div>\r<div style='float:left;width:80px;text-align:left;margin:5px 5px 0px 0px;'>\r<input id='supplier" + counter + "'type='text' value='' size='4'/>\r</div>\r<div style='float:left;width:100px;text-align:left;margin:5px 5px 0px 0px;'>\r<input id='type" + counter + "'type='text' value='' size='6'/>\r</div>\r<div style='float:left;width:85px;text-align:left;margin:5px 5px 0px 0px;'>\r<input id='deliverytime" + counter + "'type='text' value='' size='13'/>\r</div>\r<div style='float:left;width:40px;text-align:left;margin:5px 0px 0px 45px;'>\r<select id='supplyCurrency" + counter + "'>\r<option value='pound' selected='selected'>£</option><option value='dol'>$</option><option value='euro'>€</option></select>\r</div>\r<div style='float:left;width:15px;text-align:left;margin:5px 5px 0px 0px;'>\r<input onkeyup=\"advCalc(\'" + counter + "\')\" id=' supplyamount " + counter + "'type='text' value='' size='3'/>\r</div>\r<div style='float:left;width:40px;text-align:left;margin:5px 0px 0px 45px;'>\r<select name='provideCurrency" + counter + "'><option value='pound' selected='selected'>£</option><option value='dol'>$</option><option value='euro'>€</option></select>\r</div>\r<div style='float:left;width:15px;text-align:left;margin:5px 5px 0px 0px;'>\r<input onkeyup=\"advCalc(\'" + counter + "\') id=' provideamount " + counter + "' type='text' value='' size='3'/>\r</div>\r<div style='float:left;width:20px;text-align:left;margin:5px 0px 0px 45px;'>\r<strong>£</strong>\r</div>\r<div style='float:left;width:40px;text-align:left;margin:5px 5px 0px 0px;'><span id=' total " + counter + "'></span></div> \r" ; document.getElementById(divName).appendChild(newdiv) ; counter++ ; } The problem I am having is that it works fine for the first row which is hardcoded as e.g. id="provideamount0" etc. It isn't working for any other fields added but I can't see what is wrong Ok, told you I'd be asking lots of questions ... Code: <div id="resizetest" style="width:200px;height:200px;border:2px solid blue"> <div style="background:#000033"> <a href="#" style="float:right;background:#ffffff" onclick='document.getElementById("resizetest").height="50";'>_</a> </div> This is a resize test </div> Why doesn't this resize? I've looked at examples, and I don't see what's wrong. I'm coding my new website, and to save bandwidth, i'm letting users link to their own avatars, so I want to resize any images over 150px wide so it doesn't mess up my layout - simple, right? Well, you'd think so, but I don't know any javascript, so i've scrapped this together with what little I know: Code: var obj=document.getElementsByTagName("img"); for(var i=0;i<obj.length;i++){ if(obj[i].className == "avatar") { if(getElementWidth(obj[i]) > 150) { obj[i].style.width = 150; } } } Can anyone help me fix that or code me a new one please? I need it to check all elements (well, images - but only images will be using it) for a width of over 150px, and, if it is - change it to 150px I know it's pretty simple but it's hurting my head! :P Thanks in advance -Alux Hi, Ive written some code to try and resize a page dependant on the content oof an iframe. Code is as follows: Code: window.onload=sizeAdj(); function sizeAdj() { var elFrame = document.getElementById('theFrame'); var elTable = document.getElementById('tableGrab'); var elDivMain = document.getElementById('main'); var elDivWrapper = document.getElementById('wrapper'); var the_height = elFrame.contentWindow.document.body; elFrame.height = the_height; elTable.height = the_height + 90; elDivMain.height = the_height + 90; elDivWrapper.height = the_height + 465; } I originally thought that I would just be able to resize the iframe and the other elements would follow suit but as you can see Ive tried to resize the other encasing elements also. The code resizes partially in chrome but only to a certain point and not to the full height of the doc content. Help greatly appreciated - full source content attached. Rugby Glass.zip Thanks Sol Hi, Am making a user registration page and i want it to be smaller then my other pages and it should open in a new window, something like a popup window. How can i do this? Thanks Im using the below javascript to resize images on a forum I have created but I want it to ignore 2 certain images that are part of my header. Heres the code Code: <script> window.onload = resizeimg; function resizeimg() { if (document.getElementsByTagName) { for (i=0; i<document.getElementsByTagName('img').length; i++) { im = document.getElementsByTagName('img')[i]; if (im.width > 600) { im.style.width = '600px'; eval("pop" + String(i) + " = new Function(\"pop = window.open('" + im.src + "','phpbbegypt ','fullscale','width=400,height=400,scrollbars=1,resizable=1'); pop.focus();\")"); eval("im.onclick = pop" + String(i) + ";"); if (document.all) im.style.cursor = 'hand'; if (!document.all) im.style.cursor = 'pointer'; im.title = 'Click Here To See Image Full Size '; } } } } </script> But I want it to ignore 2 images..and not resize them. head1.jpg head2.jpg Any help would be gratefully recieved !! Cheers !! Hi folks! Very, very new to Javascript and I'm having a problem. What I'm trying to do is create a page that uses an iframe to show the fullsized image, while using thumbnails at the bottom. I need the iframe to resize depending on the size of the image since some are landscape and others are portrait oriented. I found a script online that did it for the height of the picture so I tried to modify it to do both the width and the height and haven't had much luck. Here's the code, and I apologize in advance for my noob coding. Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Halloween 2009</title> <script language="JavaScript"> <!-- function calcWidth() { //find the width of the internal page var the_width= document.getElementById('preview').contentWindow. document.body.scrollWidth; //change the width of the iframe document.getElementById('preview').width= the_width; } function calcHeight() { //find the height of the internal page var the_height= document.getElementById('preview').contentWindow. document.body.scrollHeight; //change the height of the iframe document.getElementById('preview').height= the_height; } //--> </script> <style type="text/css"> body {background: url(background/bg3.gif); text-align:center} img {height: 5em; width:5em; display: inline; border: none} </style> </head> <body> <div style="height: 448px"> <iframe src="Halloween '09 021.jpg" name="preview" id="preview" onLoad="calcWidth();calcHeight();" marginheight="0" marginwidth="0" scrolling="no"> An iframe capable browser is required to view this web site. </iframe> </div> <div id="thumbnails" style="padding-top: 1.5em; width: 40em; text-align: center"> <a href="Ariana.JPG" target="preview"><img src="Ariana.JPG" alt="" /></a> <a href="Halloween '09 002.jpg" target="preview"><img src="Halloween '09 002.jpg" alt="" /></a> <a href="Ayesha.jpg" target="preview"><img src="Ayesha.jpg" alt="" /></a> ETC... </div> </body> </html> Hello i would need a 1x1 pixel image for my flagcounter,ive been trying for months [IMG*]http://2.s07.flagcounter.com/count/DymW/bg=ffffff/txt=ffffff/border=ffffff/columns=1/maxflags=1/viewers=3/labels=0/[/IMG*] (the stars for the image not to appear) helllp
|