JavaScript - How To Hide Div Padding Until Visible?
If you goto http://jsfiddle.net/BT4Bk/ you can see that the dark bar is visible.
This is padding for the #ajax div that will wrap the content inside. How do I hide the padding so its not displayed until it slides into view with the content? Similar Tutorialshy. i have menu further construction Code: <ul id="menu" class="menu"> <li><a href="#">item 1  </a></li> <li><a href="#">item 2  </a></li> <li><a href="#">item 3</a> <ul id="submenu" class="submenu"> <li><a href="#">item 3 sub 1</a></li> <li><a href="#">item 3 sub 2</a></li> </ul> </li> </ul> and my function to open my on obscure menu then mouse over to element teg a Code: function doMenu (li){ var oli = li.childNodes; var len = oli.length; if (len > 1) { for (var i = 0; i < len; i++) { if (oli[i].nodeType == 1) { if (oli[i].tagName == 'UL') { return oli[i]; }}}} }; function doShow(e) { if (e) { var t = e.target; console.log(t.tagName); var pN = t.parentNode; console.log(pN) if (pN.tagName == 'LI') { if (doMenu(pN)) { var oUl = doMenu(pN); if (oUl.style.display == "none") { oUl.style.display = "block" } else {oUl.style.display = "none"} }}}}; and my problem, then HTML page load full. I mouse over to element tag a and function at this moment not show element menu. why it so. Because then i start mouse over too, function start and menu show. who can explain me how it work. Hi As title says : "How to hide div so his content won't be loaded until he is visible?" And is it possible to add preloader for that div? Hello, I am having the problem that a javascript code runs from the start (Since I open the page). My page works by divs and not web pages so they change by the div visibility. This is the code for the divs: Code: function toggleVisibility(selectedTab) { // Get a list of your content divs var content = document.getElementsByClassName('content'); // Loop through, hiding non-selected divs, and showing selected div for(var i=0; i<content.length; i++) { if(content[i].id == selectedTab) { content[i].style.display = 'block'; } else { content[i].style.display = 'none'; } } } So each DIV has a function to make it visible by posting: "toggleVisibility(div);" I am trying to run a javascript code inside this function so that when a certain div becomes available the javascript code autoruns but whenever I post the javascript code inside the function it ignoresthat and runs since the web page loads. My example code would be: Code: function div(){ toggleVisibility('div2'); "RUN JAVASCRIPT CODE HERE" } Please help Reply With Quote 01-22-2015, 09:42 AM #2 felgall View Profile View Forum Posts Visit Homepage Master Coder Join Date Sep 2005 Location Sydney, Australia Posts 6,745 Thanks 0 Thanked 666 Times in 655 Posts Stick the code to run when a div becomes visible in a separate function. If the code is different for different divs then create separate functions. Let's assume that the function containing the code to run when div2 is visible is called func2. Let's also add func1 for when div1 is visible so you can see how it works for different functions for different divs. We'll also assume div3 can use the same function as div1 so you can see how functions can be shared We then amend the toggle function slightly as follows: Code: function toggleVisibility(selectedTab, func) { // Get a list of your content divs var content = document.getElementsByClassName('content'); // Loop through, hiding non-selected divs, and showing selected div for(var i=0; i<content.length; i++) { if(content[i].id == selectedTab) { content[i].style.display = 'block'; func(selectedTab); } else { content[i].style.display = 'none'; } } } Your code to call the toggle now gets changed to: Code: function func1(selectedTab) { "RUN JAVASCRIPT CODE FOR WHEN selectedTab IS MADE VISIBLE HERE" } function func2() { "RUN JAVASCRIPT CODE FOR WHEN div2 IS MADE VISIBLE HERE" } function div(){ toggleVisibility('div2', func2); toggleVisibility('div1', func1); toggleVisibility('div3', func1); } Hi - I hope someone can help me out, I've pored over this problem for hours. The site is http://www.spacemodel.com. A doctype is set. The CSS for the navmenu is: Code: #menu { background:#262626 url(images/menu_bg.gif) repeat-x top; border-bottom:1px solid #230808; margin:0 20px; height: 49px; overflow: hidden; } #menu .mleft{background: url(images/menu_side.gif) no-repeat left; width: 100%; height: 100%;} #menu .mright{background: url(images/menu_side.gif) no-repeat right; width: 100%; height: 100%;} #menu ul { width:960px; height:100%; overflow:hidden; } #menu ul li { list-style:none; font-family:Arial, sans-serif; font-weight: 700; line-height: 49px; color:#E6E6E6; font-size:11px; text-transform:uppercase; text-align:center; background:url(images/menu_side.gif) no-repeat right 0; margin:0 0 0 25px; padding: 0 25px 0 0; } #menu a:link,#menu a:visited,#menu a:active,#menu a:hover { color:#E6E6E6; text-decoration:none; } Works fine in all other browsers and versions. Affects about 5% of visitors, but one is my client All help and insight appreciated! Laurie Hi, After much searching and head-scratching (JS is not my forte!), I adapted some code to do what I want - well, almost! So here I am back again. I need to have three divs on a page, with each separate div changing onClick. Below is the code so far. Two problems: 1) when I open it in a browser window both divs show, then the one disappears when I click on the second div leaving only the numbers. How can I change it so that both divs remain open? 2) Instead of the numbers [1], [2], etc. to change the divs, I'd like to have to just click on one single 'click here for more' to display the next div then return to the first after the last one. Can this be integrated or is it too late? Thank you! Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html> <head> <title>Switching Divs</title> <style> #one {width: 500px; height: 100 px; border: 1px solid red; } #two {width: 500px; height: 100px; border: 1px solid blue; } #three {width: 500px; height: 100px; border: 1px solid purple; } #four {width: 500px; height: 100px; border: 1px solid green; } #five {width: 500px; height: 100 px; border: 1px solid red; } #six {width: 500px; height: 100px; border: 1px solid blue; } #seven {width: 500px; height: 100px; border: 1px solid purple; } #eight {width: 500px; height: 100px; border: 1px solid green; } #propertyfrance {float: left; color: #666666; font-family: tahoma arial, verdana, sans-serif; font-size: 11px; } .propertytext {float: left; clear: right; width: 300px; height: 100px; border: 1px solid #000; } .propertyphoto {float: left; width 200px; height: 100px; border: 1px solid #cceeff; text-align: center; } #image-switch #one { padding:0px; } #image-switch #two, #image-switch #three, #image-switch #four { display:none; } #image-switch #five { padding: 0px; } #image-switch #six, #image-switch #seven, #image-switch #eight { display:none; } </style> <script type="text/javascript"> function switch1(div) { if (document.getElementById('one')) { var option=['one','two','three','four', 'five', 'six', 'seven', 'eight']; for(var i=0; i<option.length; i++) { obj=document.getElementById(option[i]); obj.style.display=(option[i]==div)? "block" : "none"; } } } </script> </head> <body> <h4>Switching divs (javascript)</h4> <div id="image-switch"> <br>OnClick <br> <div id="one"> <div class="propertytext">We'll get some text in here for property 1</div> <div class="propertyphoto"><img src="property1.jpg" height="100" width="180" alt="Property 1"></div> </div> <div id="two"> <div class="propertytext">We'll get some text in here for property 2</div> <div class="propertyphoto"><img src="property2.jpg" height="100" width="180" alt="Property 2"></div> </div> <div id="three"> <div class="propertytext">We'll get some text in here for property 3</div> <div class="propertyphoto"><img src="property3.jpg" height="100" width="180" alt="Property 3"></div> </div> <div id="four"> <div class="propertytext">We'll get some text in here for property 4</div> <div class="propertyphoto"><img src="property4.jpg" height="100" width="180" alt="Property 4"></div> </div> <br> <a onClick="switch1('one');"> [1]</a> <a onClick="switch1('two');"> [2]</a> <a onClick="switch1('three');"> [3]</a> <a onClick="switch1('four');"> [4]</a> <br><br> <div id="five"> <div class="propertytext">We'll get some text in here for property 5</div> <div class="propertyphoto"><img src="property5.jpg" height="100" width="180" alt="Property 5"></div> </div> <div id="six"> <div class="propertytext">We'll get some text in here for property 6</div> <div class="propertyphoto"><img src="property6.jpg" height="100" width="180" alt="Property 6"></div> </div> <div id="seven"> <div class="propertytext">We'll get some text in here for property 7</div> <div class="propertyphoto"><img src="property7.jpg" height="100" width="180" alt="Property 7"></div> </div> <div id="eight"> <div class="propertytext">We'll get some text in here for property 8</div> <div class="propertyphoto"><img src="property6.jpg" height="100" width="180" alt="Property 8"></div> </div> <br> <a onClick="switch1('five');"> [5] </a> <a onClick="switch1('six');"> [6] </a> <a onClick="switch1('seven');"> [7] </a> <a onClick="switch1('eight');"> [8] </a> </div> </body> </html> I have seveal flash quizzes set up for my history class. On the main page right now is just a link to quiz #1. After finishing quiz #1, I want a cookie set that is proof of a finished test. I will then redirect back to the main page that will now show a link to quiz #2. And so on after each quiz.... Any help would be greatly, greatly appreciated. I want 10 divs that have their visibility set to none. Then based on a cookie I would like to have 1 at at time become visible. Say I have a gallery of 16 images and I have a menu for the gallery to sort the images by Most Viewed, Most Recent, Highest Rating, A-Z, Z-A.. if I were to click 1 of the menu links it will change the order of the images but is it possible to actually show the images MOVING into their new places? Looking for a jquery solution if possible.. if not still open to anythin that would work Hi, have table with 5 rows. First 2 rows visible. Last 3 rows hidden - Code: <tr id="row1" style="display: none"> <tr id="row2" style="display: none"> <tr id="row3" style="display: none"> With onclick would like to make those rows visible to user - how can I do that? thank - john Hello guys, The following excerpt is part of a very huge project(in terms of code involved). Pardon me if it lacks a bit of context. But I assume I have posted adequate information for understanding the problem. Code: var sztitlebar_specific= "<table cellpadding='0px' cellspacing='0px' width='100%'><tr>" +"<td class='tiletitle'>" "<img src='../images/alert.gif' onclick='toggleAlerts(\"#ID#\")' alt='Toggle Alerts' title='Toggle Alerts' style='cursor: hand'>" + "<input type='checkbox' name='pricesonlycb' onclick='parent.applyFilterPricesOnly(\"#ID#\",pricesonlycb.checked,mypricesonlycb.checked,\"#NAME#\")'>" + "<input type='checkbox' name='mypricesonlycb' onclick='parent.applyFilterPricesOnly(\"#ID#\",pricesonlycb.checked,mypricesonlycb.checked,\"#NAME#\")'>" + "<td class='tiletitle' style='text-align: center'>#NAME#</td>" + </tr></table>"; The onclick event fires without any trouble, and the following function is called. Code: function applyFilterPricesOnly(filterid, pricesonly, mypricesonly,filtername){ alert("applyFilterPricesOnly called: filterid =" + filterid + "filtername =" + filtername + "mypricesonly =" + mypricesonly + " pricesonly=" + pricesonly); } But when I alert the status of the checkboxes they show up as "undefined". As you can see, the first piece of code defines a titlebar with a button and a couple of checkboxes and the name of the titlebar. And it is these checkboxes that remain undefined even though I can see them and check and uncheck them. But the name of the titlebar gets passed to the function correctly when the onclick event fires and it gets alerted. Where am I going wrong? Hi I'm trying to create a questionnaire style series of radio buttons which are hidden and then a different set of radio buttons displayed depending on the previous answer. eg Q1 Is it a man? (if select yes then display) Q2 Is he called John? (if no then display) Q3 Is he called Gary? and so on... I've been testing using the code below but wondered if anyone had any ideas on how this could be done easily? Be grateful for any advice, Matt. Code: Is it a Man? <input type="radio" name="agree" value="y" onClick="toggle(this)" /> Yes <input type="radio" name="agree" value="n" onClick="toggle(this)" /> No <br /> <p id="continue"> <input type="radio" name="agree" value="y" onClick="toggle(this)" /> Yes <input type="radio" name="agree" value="n" onClick="toggle(this)" /> No </p> <script> var continue_button = document.getElementById('continue'); continue_button.style.visibility = 'hidden'; function toggle(switchElement) { if (switchElement.value == 'y') continue_button.style.visibility = 'visible'; else continue_button.style.visibility = 'hidden'; } </script> Hello everyone, I have tried about 8 different variations of code to try to get this to work properly and cannot accomplish it. Please help if you can figure it out. I have 2 div's that are hidden. each div contains a FLV video, autostart=false. when button 1 is clicked, DIV 1 becomes visible and you may click on video to start playing it. When button 2 is clicked, DIV 1 goes to hidden and DIV 2 becomes visible with video 2. -- Ok so problem is this, the video that was playing in DIV 1 remains playing or at least the audio remains playing. If video 2 is started then you have 1 video source and 2 audio sources playing. I am trying to get the video in DIV 1 or DIV 2 to STOP or PAUSE when the DIV's state becomes hidden. here is the last code I tried below before frustration over come me. any suggestions would be great. Robert Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- #Layer1 { position:absolute; width:200px; height:115px; z-index:1; left: 13px; top: 47px; visibility: hidden; } #Layer2 { position:absolute; width:600px; height:645px; z-index:2; left: 14px; top: 47px; visibility: hidden; } --> </style> <script type="text/JavaScript"> <!-- function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_showHideLayers() { //v6.0 var i,p,v,obj,args=MM_showHideLayers.arguments; for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; } obj.visibility=v;} } function MM_popupMsg(msg) { //v1.0 alert(msg); } //--> </script> </head> <img src="chastain cd landing pages/atlanta-ga-carpet-upholstery-cleaning.com/images/phone.jpg" alt="Button to Display DIV 1" width="27" height="22" onclick="MM_showHideLayers('Layer1','','show','Layer2','','hide')" /> <img src="chastain cd landing pages/atlanta-ga-carpet-upholstery-cleaning.com/images/spacer.gif" width="60" height="1" /> <img src="chastain cd landing pages/atlanta-ga-carpet-upholstery-cleaning.com/images/phone.jpg" alt="Button to Display Div 2" width="27" height="22" onclick="MM_showHideLayers('Layer1','','hide','Layer2','','show')"/> <div id="Layer1">VIDEO 1 <object id="player1" type="application/x-shockwave-flash" width="600" height="600" wmode="transparent" data="http://www.dryconcepts.com/videos/flvplayer.swf?file=http://www.dryconcepts.com/videos/video1.flv&autoStart=false"> <param name="movie" value="http://www.dryconcepts.com/videos/flvplayer.swf?file=http://www.dryconcepts.com/videos/video1.flv&autoStart=false" /> <param name="wmode" value="transparent" /> </object> </div> <div id="Layer2">VIDEO 2 <object id="player2" type="application/x-shockwave-flash" width="600" height="600" wmode="transparent" data="http://www.dryconcepts.com/videos/flvplayer.swf?file=http://www.dryconcepts.com/videos/video1.flv&autoStart=false"> <param name="movie" value="http://www.dryconcepts.com/videos/flvplayer.swf?file=http://www.dryconcepts.com/videos/video1.flv&autoStart=false" /> <param name="wmode" value="transparent" /> </object> </div> </body> </html> Hello, months when I want all the fields will be filled submit will be visible on all but I just do what has not n'arive test Note b: there is already invisible submit send # I hope the idea is clear Maintenon. here is my code jQuery: Code: $(document).ready(function() { //------------------ validation champ email par blur ------------- $("#email,#objet,#message").blur(function() { var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if ($("#email").val() !== "E-mail" && $("#email").val() !== "" && $("#email").val().match(filter) && $("#objet").val() !== "" && $("#objet").val() !== "Objet" && $("#message").val()!== "" && $("#message").val()!== "Votre message") { $("#objet,#message,#email").css("border-color","#98D100"); $("#envoyer").fadeIn(2000); alert('les champs valid'); return true; } else { $("#objet,#message,#email").css("border-color","#FF0000"); $("#envoyer").fadeOut(2000); alert('les champs not valid'); return false; } }); //--------------- animation de champ message ----------------- $("#message").focus(function(){ $("#message").animate({ height: "50px" }, 1000 ); }); }); here is the html code: Code: <input id="email" type="text" value="E-mail" onFocus="if (this.value=='E-mail') {this.value=''}"/> <div class="cl"></div> <input id="objet" type="text" value="Objet" onFocus="if (this.value=='Objet') {this.value=''}"/> <div class="cl"></div> <textarea id="message" type="text" value="Votre message" onFocus="if(this.value=='Votre message') {this.value=''}">Votre message</textarea> <div class="cl"></div> <input id="envoyer" type="submit" value="Envoyer"/> Regards. Site: www.ameego.co.uk I am having problems with the padding on my drop-down java menu. I want the width to automatically vary on the different categories such as 'Batteries' and 'Replacement Parts' for example. At the moment, I have a set width, and thats fine for some categories, but others, such as 'Batteries' there is not enough information to fill it and it looks like a ugly blank space. I was wondering how I can change the HTML/CSS so that it will vary in size for each individual category. Here is my current CSS coding: Code: /* ######### Shared basic style for mega drop down menu DIV ######### */ .mega{ width: 450px; padding: 10px; position:absolute; visibility:hidden; border:2px solid black; border-top-width:1px; background:GREY; -webkit-box-shadow: 5px 5px 5px #c8c8c8; /*css 3 shadows*/ -moz-box-shadow: 5px 5px 5px #c8c8c8; box-shadow: 5px 5px 5px #c8c8c8; } .mega .column{ /*each link column within a mega menu*/ float:left; width:49%; } .mega a{ text-decoration:none; } .mega a[rel]:after{ /*add "down.png" to anchor links, or those with a rel attribute */ content:" " url(down.png); } .mega .column ul{ margin:0; margin-left:5px; padding:0; list-style:none; } .mega .column ul li{ margin-bottom:3px; } .mega .ulmenu{ /*style any UL within mega menu with class="ulmenu"*/ margin:0; padding:0; border:1px solid gray; border-bottom-width:0; list-style:none; } .mega .ulmenu a{ display:block; border-bottom:1px solid gray; padding:5px; } .mega .ulmenu a:hover{ background:lightyellow; } } li#scroll-tablets a.scroll1:hover, li#scroll-tablets a.scroll2:hover { -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; -moz-box-shadow:0 0 10px #ef5f27; -webkit-box-shadow:0 0 10px #ef5f27; box-shadow:0 0 10px #ef5f27; border: 1px dotted #ef5f27; } /* ######### Style for Solid Block Mega Menu ######### */ .solidblocktheme{ /*additional mega drop down menu style for this theme*/ border:2px solid #000000; padding:0; /*remove default padding inside mega menu*/ } .solidblocktheme p, .solidblocktheme .column{ padding:5px; /*add padding inside p and .column elements within mega menu*/ width:auto; } .solidblockmenu{ margin: 0; padding: 0; float: left; font: bold 13px Tahoma; width: 100%; overflow: hidden; margin-bottom: 1em; border: 1px solid #625e00; border-width: 1px 0; background: black url(blockdefault.gif) center center repeat-x; } .solidblockmenu li{ display: inline; } .solidblockmenu li a{ float: left; color: white; padding: 9px 11px; text-decoration: none; border-right: 1px solid white; } .solidblockmenu li a:visited{ color: white; } .solidblockmenu li a:hover, .solidblockmenu li a.selected{ /*Selected Tab style*/ color: white; background: transparent url(blockactive.gif) center center repeat-x; } Thanks in advance I have the following code ... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <style type="text/css"> body { background-color:#000; } #scenery { width:964px; height:482px; padding:318px 0 0 316px; margin:auto; background-image:url('http://www.deshow.net/d/file/travel/2009-10/new-zealand-scenery-738-20.jpg'); } </style> </head> <body> <div id="scenery"> <img src="http://cdn3.iconfinder.com/data/icons/softwaredemo/PNG/128x128/DrawingPin1_Blue.png" alt=""> </div> </body> </html> ... in which I would like to use Javascript to control the values in the 'padding'. Code: padding:318px 0 0 316px; May I know how can I use Javascript to control that 'padding' values? Appreciate any help. Hi, Here's a sample division: Code: <div style="padding:0 0 0 30px; background:url(http://www.google.com/help/hc/images...ent_bubble.gif) left center no-repeat;">some text</div> I wonder how I can calculate the padding-left:30px dynamically so that any icon I choose the padding-left value changes according to the image width. Any help is appreciated! Hello all, I need to get the border and internal padding width of a cell of a table. I plan to subtract these values from the offsetWidth to get the content width, and use that to set the style.width of another cell. Unfortunately, I can't find a tried-and-true way to get the border and padding width. Anyone got an idea? Hi all, Check this code: PHP Code: <a>text</a> <div id="pkg">pkg</div> <div id="table_pkg">table_pkg</div> I'd like to show table_pkg and hide pkg when I click on <a>text</a>. How can I do? Thank you very much Hello, I have the folowing code but it seems to be broken between "SM Decision Support" and "Incident and Request Management". Does anyone know how I resolve ?. The idea is when somebody opens the page all the sections are hidden/uncollapsed and the user can collapse individually each section with a click or by hitting the expand/collapse all link. ------------ Have placed code in attachment as too long for this section |