treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Fading menu -- can't get more than three to work

  • Hi there-
    Using the fading jquery menu/content code from here:

    http://css-tricks.com/learning-jquery-f ... g-content/

    Works great (LOVE the effect), but I can't get more than three to work (the demo had three) and even though I've renamed things and matched up with button name with the content div names, the content divs past the first three don't appear. Or if someone knows of an easier way to get this effect, that'd be awesome too. Thanks in advance!

    Code pasted here (and if you want to see it in action: http://lizhoff.com/bpoint/services.html)

    javascript:
    <script type=\"text/javascript\">

    $(function(){

    $(\"#page-wrap div.button\").click(function(){

    $clicked = $(this);

    // if the button is not already \"transformed\" AND is not animated
    if ($clicked.css(\"opacity\") != \"1\" && $clicked.is(\":not(animated)\")) {

    $clicked.animate({
    opacity: 1,
    }, 400 );

    // each button div MUST have a \"xx-button\" and the target div must have an id \"xx\"
    var idToLoad = $clicked.attr(\"id\").split('-');

    //we search trough the content for the visible div and we fade it out
    $(\"#content\").find(\"div:visible\").fadeOut(\"fast\", function(){
    //once the fade out is completed, we start to fade in the right div
    $(this).parent().find(\"#\"+idToLoad[0]).fadeIn();
    })
    }

    //we reset the other buttons to default style
    $clicked.siblings(\".button\").animate({
    opacity: 0.3,
    borderWidth: 1
    }, 400 );

    });
    });

    </script>

    <html>
    <div id=\"page-wrap\">
    <div style=\"float:left;\">
    <div id=\"electrical-button\" class=\"button\">Electrical Inspections </div>
    <div id=\"pipe-button\" class=\"button\">Pipe Inspections </div>
    <div id=\"mechanical-button\" class=\"button\">Mechanical Inspections </div>
    <div id=\"roof-button\" class=\"button\">Roof Moisture Inspections </div>
    <div id=\"energy-button\" class=\"button\">Energy Conservation</div>
    <div id=\"boiler-button\" class=\"button\">Boiler Efficiency</div>
    <div id=\"steam-button\" class=\"button\">Steam trap Inspections</div>
    </div>
    <div style=\"float:left; margin-left:20px; width:400px;\">
    <div id=\"content\">
    <div id=\"electrical\">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor, urna quis tincidunt consequat, dolor urna gravida sem, id malesuada risus tortor imperdiet quam. Integer ipsum ipsum, volutpat sed molestie non, pharetra vitae elit. Mauris tristique eleifend magna, accumsan consequat ante rhoncus sed. Sed pellentesque enim eu nibh congue vitae aliquam nisi sodales. Quisque eu lectus ac quam laoreet elementum sed et leo. Morbi tristique ante blandit nisl porta faucibus. </p></div>
    <div id=\"pipe\">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor, urna quis tincidunt consequat, dolor urna gravida sem, id malesuada risus tortor imperdiet quam. Integer ipsum ipsum, volutpat sed molestie non, pharetra vitae elit. Mauris tristique eleifend magna, accumsan consequat ante rhoncus sed. Sed pellentesque enim eu nibh congue vitae aliquam nisi sodales. Quisque eu lectus ac quam laoreet elementum sed et leo. Morbi tristique ante blandit nisl porta faucibus. </p></div>
    <div id=\"mechanical\">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor, urna quis tincidunt consequat, dolor urna gravida sem, id malesuada risus tortor imperdiet quam. Integer ipsum ipsum, volutpat sed molestie non, pharetra vitae elit. Mauris tristique eleifend magna, accumsan consequat ante rhoncus sed. Sed pellentesque enim eu nibh congue vitae aliquam nisi sodales. Quisque eu lectus ac quam laoreet elementum sed et leo. Morbi tristique ante blandit nisl porta faucibus. </p></div>
    <div id=\"roof\" style=\"display:none;\">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tempor, urna quis tincidunt consequat, dolor urna gravida sem, id malesuada risus tortor imperdiet quam. Integer ipsum ipsum, volutpat sed molestie non, pharetra vitae elit. Mauris tristique eleifend magna, accumsan consequat ante rhoncus sed. Sed pellentesque enim eu nibh congue vitae aliquam nisi sodales. Quisque eu lectus ac quam laoreet elementum sed et leo. Morbi tristique ante blandit nisl porta faucibus. </p></div>
    </html>

    Many thanks!
    Liz
  • Hi Liz,

    It looks like you only have three boxes of content to appear... ? The fourth button is supposed to show the Roof div, but I can't find it... (The Jquery probably can't find it either.)

    It looks like the code you pasted is different then the code on the site.

    The code you pasted has a little bit of a </div> problem. It looks like you ended a div before you should have. make sure you validate your HTML.

    http://validator.w3.org/check?verbose=1 ... r-url-here


    Let me know.
  • Haha it WAS a <div> problem. I had closed the #page_wrap too soon. Thanks!
  • No Problem. Glad that fixed it.