JavaScript - Expandable Sticky Bar
Hey guys,
I own an online internet radio station and I have many different way which people can tune in. One way is the browse 'n' play feature. The browse 'n' play feature allows you to browse the net at the same time as being tuned into the radio. Below, I have installed an 'Expandable Sticky Bar' which is used for the radio panel. http://www.dynamicdrive.com/dynamici.../stickybar.htm What I am trying to do, is simply add that bar on every page my visitors visit. So, when the listen chooses 'Browse 'n' Play' I want a new window or tab to open, with Google and my bar at the bottom. I cannot figure out how I could do this, any ideas on how I could make this happen? Thanks. Similar TutorialsI just got this problem when I try to add the expandable divs in my webpage. However when I click the divs on the page, I can't see the rest of my content. This is my page, does anybody know what happened with my code??!! http://www.calibredesign.com/clients..._news_new.html the divs are on the button of the page. Thanks!! Hi, I'm completely new to using JavaScript having never used it before so please forgive me if this is ridiculously easy to solve. I want to include an expandable FAQ section in part of my website. I managed to find some code that works however by default the sections are expanded. I want them to automatically be collapsed when the page loads and when you click the image it then expands and shows the hidden text. The code I found is Code: <head><title> Untitled Page </title> <script type="text/javascript"> function expandable_toggle(id) { var tr = document.getElementById(id); if (tr==null) { return; } var bExpand = tr.style.display == ''; tr.style.display = (bExpand ? 'none' : ''); } function expandable_changeimage(id, sMinus, sPlus) { var img = document.getElementById(id); if (img!=null) { var bExpand = img.src.indexOf(sPlus) >= 0; if (!bExpand) img.src = sPlus; else img.src = sMinus; } } function Toggle_trGrpHeader1() { expandable_changeimage('trGrpHeader1_Img', 'images/minus.gif', 'images/plus.gif'); expandable_toggle('trRow1'); } function Toggle_trGrpHeader2() { expandable_changeimage('trGrpHeader2_Img', 'images/minus.gif', 'images/plus.gif'); expandable_toggle('row1'); } </script> </head> <body> <div> <table border="0"> <tr id="trGrpHeader1"> <td colspan="4"><span onclick="javascript:Toggle_trGrpHeader1();"><img src="images/minus.gif" id="trGrpHeader1_Img"/>Pretend this is a header for row 1</span></td> </tr> <tr id="trRow1"> <td> Hello<br><br></td></tr> <tr id="trGrpHeader2"><td colspan="4"><span onclick="javascript:Toggle_trGrpHeader2();"><img src="images/minus.gif" id="trGrpHeader2_Img"/>Pretend this is a header</span></td> </tr> <tr id="row1"> <td> 123</td></tr> </table> </div> </body> </html> Any help you can give would be greatly appreciated. Many thanks hi, i got a expandable menu that is working. i wonder if there is any way to make the links show as html and css if the user has disabled javascript i my code including javascript and css <!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=utf-8" /> <title>Untitled Document</title> <script language="JavaScript" type="text/JavaScript"> <!-- menu_status = new Array(); function showHide(theid){ if (document.getElementById) { var switch_id = document.getElementById(theid); if(menu_status[theid] != 'show') { switch_id.className = 'show'; menu_status[theid] = 'show'; }else{ switch_id.className = 'hide'; menu_status[theid] = 'hide'; } } } //--> </script> <style type="text/css"> .menu1{ margin-left:25px; padding-left:20px; padding-top:2px; padding-bottom: 2px; display:block; text-decoration: none; color: #000000; height: 20px; width: 200px; background-color: #03C; border: thin solid #FFF; } .submenu{ background-image: url(images/submenu.gif); display: block; height: 19px; margin-left: 38px; padding-top: 2px; padding-left: 7px; color: #333333; } .hide{ display: none; } .show{ display: block; } </style> </head> <body> <a class="menu1" onclick="showHide('mymenu1')">Menu 1</a> <div id="mymenu1" class="hide"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu2')">Menu 2 </a> <div id="mymenu2" class="hide"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu3')">Menu 3 </a> <div id="mymenu3" class="hide"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu4')">Menu 4 </a> <div id="mymenu4" class="hide"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> <a class="menu1" onclick="showHide('mymenu5')">Menu 5 </a> <div id="mymenu5" class="hide"> <a href="#" class="submenu">Link One here</a> <a href="#" class="submenu">Link Two here</a> <a href="#" class="submenu">Link Three here</a> <a href="#" class="submenu">Link Four here</a> </div> </body> </html> Hello, I'm pretty new to JS but I can script a few things. I'm using a pre-written script, but trying to add a functionality that uses my + and - images to indicate whats whether the list is expanded or not. It works on the first click. The symbol starts as a plus, you click it and it expands and goes to minus. After that the list maintains functionality (for the most part) but doesn't continue changing symbols back and forth. I've pored over the script for HOURS but I can't find the solution. Working Link Example My written JS: Code: // JavaScript Document var expandables = new Array(); expandables[0] = "expand_northeast"; expandables[1] = "expand_southeast"; expandables[2] = "expand_midwest"; expandables[3] = "expand_southwest"; expandables[4] = "expand_west"; var clickCounter = 0; function expand(current) { //add height to the containing div if(clickCounter<=1) { var newHeight = document.getElementById('region_us').offsetHeight + 187; document.getElementById('region_us').style.height = newHeight.toString() + 'px'; clickCounter+=1; } //get the section name var section = current.split('_')[1]; for ( var i=0; i<expandables.length; i++ ){ if(document.getElementById(expandables[i]).id.indexOf('collapse') != -1){ //if it has collapse in id string var tempSection = expandables[i].split('_')[1]; //parse just the region document.getElementById(expandables[i]).id='expand_' + tempSection; //change the id to expand / plus symbol expandables[i] = document.getElementById('expand_' + tempSection).id; //make the change in the array as well } } document.getElementById(current).href='javascript:animatedcollapse.show(\'stats_'+ section + '\');'; document.getElementById(current).onclick=function() {collapse('\'collapse_'+section +'\'');}; document.getElementById(current).id="collapse_" + section + ""; for (x in expandables) { if(expandables[x] == current){ expandables[x] = document.getElementById('collapse_' + section).id; } } //alert(expandables); } function collapse(current) { var section = current.split('_')[1]; //alert(current); current = ("expand_"+section); document.getElementById(current).href='javascript:animatedcollapse.hide(\'stats_'+ section + ');'; document.getElementById(current).onclick=function() {expand('"expand_'+section+'"');}; document.getElementById(current).id='expand_' + section; for (x in expandables) { if(expandables[x] == current){ expandables[x] = document.getElementById('expand_' + section).id; } } } Relevant HTML: Code: <a id="expand_northeast" href="javascript://" onclick="expand('expand_northeast');"></a> <span class="state_title">Northeast</span> <span class="state_title_num">2,749</span> <span class="state_title_perc">62.5%</span> <div id="stats_northeast" style="display:none;"> <span class="state colored">Maine</span><span class="stat_num colored">32</span><span class="stat_percent colored">7.1%</span><br /> <span class="state">New Hampshire</span><span class="stat_num">32</span><span class="stat_percent">7.1%</span><br /> <span class="state colored">Rhode Island</span><span class="stat_num colored">32</span><span class="stat_percent colored">7.1%</span><br /> <span class="state">New Hampshire</span><span class="stat_num">32</span><span class="stat_percent">7.1%</span><br /> <span class="state colored">Rhode Island</span><span class="stat_num colored">32</span><span class="stat_percent colored">7.1%</span><br /> <span class="state">New Hampshire</span><span class="stat_num">32</span><span class="stat_percent">7.1%</span><br /> <span class="state colored">Rhode Island</span><span class="stat_num colored">32</span><span class="stat_percent colored">7.1%</span><br /> <span class="state">New Hampshire</span><span class="stat_num">32</span><span class="stat_percent">7.1%</span><br /> <span class="state colored">Maryland</span><span class="stat_num colored">32</span><span class="stat_percent colored">7.1%</span><br /> <span class="state">Pennsylvania</span><span class="stat_num">32</span><span class="stat_percent">7.1%</span><br /> </div> Thanks guys! I want to create a link which doesn't takes you to anew page but just expands to show it's information . Exactly like the one in FAQs where you click the question and the page expands to show you the answer.
Hello, I was wondering whether it is possible to expand and collapse forum categories using JavaScript. The forum board I am using is phpBB. I am building an elearning site where the user is taken through a series of dynamically driven pages to refine their choices. I am using php amd mysql to populate a series of tables but on the last page the table gets very long so i am trying to make the table expandable. I found this and this on http://www.javascripttoolbox.com/jquery/ and it's proving helpful but i need a little help taking it a step further. I also found this to be useful for anyone else who is trying to do the same thing: http://www.jankoatwarpspeed.com/post...nd-plugin.aspx FROM JAVASCRIPTTOOLBOX A common UI is to have a table of data rows, which when clicked on expand to show a detailed breakdown of "child" rows below the "parent" row. The only requirements a 1. Put a class of "parent" on each parent row (tr) 2. Give each parent row (tr) an id 3. Give each child row a class of "child-ID" where ID is the id of the parent tr that it belongs Original code: Code: $(function() { $('tr.parent') .css("cursor","pointer") .attr("title","Click to expand/collapse") .click(function(){ $(this).siblings('.child-'+this.id).toggle(); }); $('tr[@class^=child-]').hide().children('td'); }); This works great but my parent and child rows all contain checkboxes and If i try and check the checkboxes in the master rows the child rows associated with that master row expand and contract. I have added an extra cell to each row and i'm using a css class to add an arrow image to each master row but i am new to Javascript so i am not sure what i am doing. My code now looks like this: Code: $(document).ready(function() { $('tr:not(.parent)').hide(); //$('tr.parent') $('.arrow') .css("cursor","pointer") .attr("title","Click to expand/collapse") .click(function(){ $(this).siblings('.child-'+this.id).toggle(); $(this).toggleClass("up"); }); }); So far the arrow image is toggling but i can't seem to work out how to get the .click function to affect the whole row and not just the image. Can anybody help me? Thanks Trying to put my finger on how to achieve this result. About half way down on the page linked below you'll see "Recent - Comments - Popular - Tags" this table expands when you rollover and stays expanded while allowing you to populate the different content. Any help would be greatly appreciated, not even sure if I'm in the right forum. http://thedailydisney.com/blog/2010/...magic-kingdom/ Thanks for the time. Will Hi, I have a web form that I'm creating and it has some expandable checkboxes that need to be restricted based on choice. This is my criteria: If someone chooses checkbox number 1, they cannot choose any other checkbox. If someone chooses checkbox number 2, they may also choose number 3 but not 1 or 4, they must also answer the question that appears below. If someone chooses checkbox number 3, they may also choose number 2 but not 1 or 4, they must also answer the question that appears below. If someone chooses checkbox number 4, they cannot choose any other checkbox, and must answer the questions that appears below. One more caveat: If checkbox number 2 is chosen, and they've filled in all three lines of the question below, I need for them to dynamically add more lines as needed. I have attached my web form so you can see what I've done. I've researched these options and tried code from various examples but I can't seem to get it to work. Does anyone know how to accomplish all of this? Thank you in advance! Hey thanks in advance to anyone who can take a peak at my code and hopefully point me in the correct direction. I have been working on my final project in my javascript class for a bit, and there are a few erros I cant seem to find through firebug or error console. It is due this evening at midnight, so anyone that could help, I really need this assignment for a decent grade. Basically there are two issues so far, one needs to be solved so the other can be as well. First, line 103 - 105 should create a hyperlink to the specified id, but is doesn't return a number. so the link goes no where it is this code: PHP Code: //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; Next I belive there is a problem with the function expandCollapseDoc(), that might fix itself when the other problem is solved. The document should expand and collapse with the menu. Here is my javascript code: PHP Code: /* New Perspectives on JavaScript, 2nd Edition Tutorial 7 Tutorial Case Author: Mike Cleghorn Date: 2-15-10 Filename: toc.js Global Variables: sections An array contain the HTML elements used as section headings in the historic document Functions List: addEvent(object, evName, fnName, cap) Adds an event hander to object where evName is the name of the event, fnName is the function assigned to the event, and cap indicates whether event handler occurs during the capture phase (true) or bubbling phase (false) makeTOC() Generate a table of contents as a nested list for the contents of the "doc" element within the current Web page. Store the nested list in the "toc" element. levelNum(node) Returns the level number of the object node. If the object node does not represent a section heading, the function returns the value -1. createList() Goes through the child nodes of the "doc" element searching for section headings. When it finds a section heading, a new entry is added to the table of contents expandCollapse() Expands and collapse the content of the table of contents and the historic document expandCollapseDoc() Goes through the child nodes of the "doc" element determining which elements to hide and which elements to display isHidden(object) Returns a Boolean value indicating whether object is hidden (true) or not hidden (false) on the Web page by examining the display style for object and all its parent nodes up to the body element */ function addEvent(object, evName, fnName, cap) { if (object.attachEvent) object.attachEvent("on" + evName, fnName); else if (object.addEventListener) object.addEventListener(evName, fnName, cap); } addEvent(window, "load", makeTOC, false); var sections = new Array("h1","h2","h3","h4","h5","h6"); var sourceDoc; //document on which TOC is based on function makeTOC(){ var TOC = document.getElementById("toc"); TOC.innerHTML = "<h1>Table of Contents</h1>"; var TOCList = document.createElement("ol"); TOC.appendChild(TOCList); sourceDoc = document.getElementById("doc"); //generate list items containing section headings createList(sourceDoc, TOCList); } function levelNum(node) { for (var i = 0; i < sections.length; i++) { if(node.nodeName == sections[i].toUpperCase()) return i; } return -1; //node is not section heading } function createList(object, list) { var prevLevel = 0; //level of the pervious TOC entry var headNum = 0; //running count of headings for (var n = object.firstChild; n != null; n = n.nextSibling) { //loop through all nodes in object var nodeLevel = levelNum(n); if (nodeLevel != -1) { //node represents a section heading //insert id for the section heading if necessary headNum++; //create list item to match var listItem = document.createElement("li"); listItem.id = "TOC" + n.id; //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; //append the hypertext to the list entry listItem.appendChild(linkItem); if (nodeLevel == prevLevel) { //append the entry to the current list list.appendChild(listItem); } else if (nodeLevel > prevLevel) { //append entry to new nest list var nestedList = document.createElement("ol"); nestedList.appendChild(listItem); list.lastChild.appendChild(nestedList); //add plus/minus box beffore the text var plusMinusBox = document.createElement("span"); plusMinusBox.innerHTML = "--"; addEvent(plusMinusBox, "click", expandCollapse, false) nestedList.parentNode.insertBefore(plusMinusBox, nestedList.previousSibling); list = nestedList; prevLevel = nodeLevel; } else if (nodeLevel < prevLevel) { //append entry to a higher-level list var levelUp = prevLevel - nodeLevel; for (var i = 1; i<= levelUp; i++) {list = list.parentNode.parentNode;} list.appendChild(listItem); prevLevel = nodeLevel; } } } } function expandCollapse(e) { var plusMinusBox = e.target || event.srcElement; var nestedList = plusMinusBox.nextSibling.nextSibling; //Toggle the plus and minus symbol if (plusMinusBox.innerHTML == "--") plusMinusBox.innerHTML = "+" else plusMinusBox.innerHTML = "--"; //Toggle display of nested list if(nestedList.style.display == "none") nestedList.style.display = "" else nestedList.style.display = "none"; //expand/collapse doc to match TOC expandCollapseDoc(); } function expandCollapseDoc() { var displayStatus = ""; for (var n = sourceDoc.firstChild; n != null; n = n.nextSibling) { var nodeLevel = levelNum(n); if (nodeLevel != -1) { //determain display status of TOC entry var TOCentry = document.getElementById("TOC" + n.id); if (isHidden(TOCentry)) displayStatus = "none" else displayStatus = ""; } if (n.nodeType == 1) { //apply to current status for the node n.style.display = displayStatus; } } } function isHidden(object) { for (var n = object; n.nodeName != "BODY"; n = n.parentNode) { if (n.style.display = "none") return true; } return false; } the html was too long, so i uploaded it to my webspace you can check out the almost working version at http://www.kinetic-designs.net/final/usconst.htm Again thank you so much! Any questions just ask! Hi, I'm trying to make a "sticky footer" that will stay at the bottom of the page and be about 2/3 of the page height. Then, when a button is clicked, the footer will slide down and be only about 1/3 the page height, collapsing the paragraphs on the footer and revealing the content the footer was covering. My first try at this is to make 3 divs within the sticky footer, and make the middle div the collapsable/expandable div. VERY hasty example, it will be a brown paper bag with art supplies inside. Issue A: What is the best way to create the smooth collapse/expand effect on the middle div using javaScript or jQuery? Issue B: All of the CSS based sticky footer fixes that I've found require the main div to have a bottom padding or margin of the footer's height. How can I fix this for the footer's two heights (with and without the middle section)? Is there a javaScript or jQuery way to do an expandable sticky footer? Issue C: The sticky footer fix makes it so that the bottom footer doesn't cover the content above it, but I WANT it to cover the content in this case, is there a better way to do this? Absolute positioning the footer? Html Code: <body> <div id="whole"> <div id="push"></div> </div> <div id="top"></div> <div id="hide"></div> <div id="bottom"></div> </body> Css Code: *{margin:0} html, body {height: 100%;} #whole { background-color: #09F; min-height: 100%; height: auto; height: 100%; margin: 0 auto -150px;} #push {min-height:150px; height:auto;} #top { height: 50px; clear:both; background-color:yellow;} #hide { min-height: 50px; height:200px; clear:both; background-color:green;} #bottom { height: 50px; clear:both; background-color:red;} Hello i have a sticky tooltip that when is in "sticky mode" the only way to close it is by clicking outside of it. I wanted to add a mouseover link for a close link so it can also be closed that way. original code: http://www.dynamicdrive.com/dynamici...ckytooltip.htm this is my external .js code and if you look about 11 lines down i have the mouseover link setup for the word "CloseMe". However that's where i need to know how to call it properly? Quote: /* Sticky Tooltip script (v1.0) * Created: Nov 25th, 2009. This notice must stay intact for usage * Author: Dynamic Drive at http://www.dynamicdrive.com/ * Visit http://www.dynamicdrive.com/ for full source code */ var stickytooltip={ tooltipoffsets: [5, -5], //additional x and y offset from mouse cursor for tooltips fadeinspeed: 1, //duration of fade effect in milliseconds rightclickstick: true, //sticky tooltip when user right clicks over the triggering element (apart from pressing "s" key) ? stickybordercolors: ["black", "darkred"], //border color of tooltip depending on sticky state stickynotice1: ["To Sticky:", "Press Key \"c\"", "or Right click"], //customize tooltip status message stickynotice2: "Sticky Activated! <a onMouseOver=javascript:LOSTT.HELPP('mystickytooltip'); href=google.com>CloseMe</a>", //customize tooltip status message //***** NO NEED TO EDIT BEYOND HERE isdocked: false, positiontooltip:function($, $tooltip, e){ var x=e.pageX+this.tooltipoffsets[0], y=e.pageY+this.tooltipoffsets[1] var tipw=$tooltip.outerWidth(), tiph=$tooltip.outerHeight(), x=(x+tipw>$(document).scrollLeft()+$(window).width())? x-tipw-(stickytooltip.tooltipoffsets[0]*2) : x y=(y+tiph>$(document).scrollTop()+$(window).height())? $(document).scrollTop()+$(window).height()-tiph-10 : y $tooltip.css({left:x, top:y}) }, showbox:function($, $tooltip, e){ $tooltip.fadeIn(this.fadeinspeed) this.positiontooltip($, $tooltip, e) }, hidebox:function($, $tooltip){ if (!this.isdocked){ $tooltip.stop(false, true).hide() $tooltip.css({borderColor:'black'}).find('.stickystatus:eq(0)').css({background:this.stickybordercol ors[0]}).html(this.stickynotice1) } }, docktooltip:function($, $tooltip, e){ this.isdocked=true $tooltip.css({borderColor:'darkred'}).find('.stickystatus:eq(0)').css({background:this.stickyborderc olors[1]}).html(this.stickynotice2) }, init:function(targetselector, tipid){ jQuery(document).ready(function($){ var $targets=$(targetselector) var $tooltip=$('#'+tipid).appendTo(document.body) if ($targets.length==0) return var $alltips=$tooltip.find('div.atip') if (!stickytooltip.rightclickstick) stickytooltip.stickynotice1[1]='' stickytooltip.stickynotice1=stickytooltip.stickynotice1.join(' ') stickytooltip.hidebox($, $tooltip) $targets.bind('mouseenter', function(e){ $alltips.hide().filter('#'+$(this).attr('data-tooltip')).show() stickytooltip.showbox($, $tooltip, e) }) $targets.bind('mouseleave', function(e){ stickytooltip.hidebox($, $tooltip) }) $targets.bind('mousemove', function(e){ if (!stickytooltip.isdocked){ stickytooltip.positiontooltip($, $tooltip, e) } }) $tooltip.bind("mouseenter", function(){ stickytooltip.hidebox($, $tooltip) }) $tooltip.bind("click", function(e){ e.stopPropagation() }) $(this).bind("click", function(e){ if (e.button==0){ stickytooltip.isdocked=false stickytooltip.hidebox($, $tooltip) } }) $(this).bind("contextmenu", function(e){ if (stickytooltip.rightclickstick && $(e.target).parents().andSelf().filter(targetselector).length==1){ //if oncontextmenu over a target element stickytooltip.docktooltip($, $tooltip, e) return false } }) $(this).bind('keypress', function(e){ var keyunicode=e.charCode || e.keyCode if (keyunicode==99){ //if "c" key was pressed stickytooltip.docktooltip($, $tooltip, e) } }) }) //end dom ready } } //stickytooltip.init("targetElementSelector", "tooltipcontainer") stickytooltip.init("*[data-tooltip]", "mystickytooltip") below is my html code Quote: <a href="http://www.link2.com"><img src="http://www.dynamicdrive.com/ddincludes/logo.gif" data-tooltip="id1" /></img></a> <div id="mystickytooltip" class="stickytooltip"> <div style="padding:5px"> <div class="stickystatus"></div> <div id="id1" class="atip" style="width:200px"> <iframe src="http://www.link.com"></iframe></div> </div></div> |