Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post

    Sliding divs... =P

    Hi there,

    I'm having some trouble with closing / opening / moving divs.

    The idea is that when i click on a persons name, to the right of that opens a div of about 400 x 400 which contains their biography.

    Basicly, the persons names in the black boxes over in this example:
    http://www.i-marco.nl/weblog/jquery-accordion-menu/#
    and then when u click on the black 'link', it opens up 1 submenu item containing and img or anything. (so 1 <li><img src =' bla ' ></li>

    And to the right as specified earlier, of about the same height as the div with biography titles and the 1 expanded picture at a time, which will initially not be visible ( since no person is selected yet. )

    Ofcourse I have some jquery code, but Its not my best..
    Now it just moves it to the right... >.<

    Any help ?

    Greatly appreciated!
    the jquery:

    Code:
    $(document).ready(function() {
      var $topLinks2 = $('#tab-nav-2 > ul > li > a');
      var $topLinksbio = $('#tab-nav-2 > ul > li > ul > li');
      $topLinks2.click(function() {
        var $parentItem = $(this).parent(),
            slideAmt = $(this).next().width(),
            direction;
        $topLinks2.removeClass('expanded');
        $topLinksbio.hide();
        if (parseInt($parentItem.css('marginLeft'), 10) > 0) {
          direction = '-=';
        } else {
          $(this).addClass('expanded');
          $topLinksbio.show();
          direction = '+=';
        }
        $parentItem
          .animate({marginLeft: direction + slideAmt}, 400)
            .siblings()
            .animate({marginLeft: '0'}, 300);
        return false;
      });
    });
    The css:
    Code:
    /* nav wrapper */
    .container {
          width: 610px;
          margin: 40px auto;
          text-align: left;
        }
        .tab-nav {
          width: 610px;
          overflow: hidden;
          background: #ddd url(tab-slide.png) no-repeat 0 0;
        }
        
        .tab-nav ul {
          position: relative;
          float: left; 
          width: 1600px;
          margin-right: 535px; 
          padding-left: 0;
          list-style-type: none;
          background-color: #fff;
        }
        .tab-nav li { 
          float: left;
          clear: left; 
        }
    
        .tab-nav a {
          display: block;
          width: 200px;
          border-right: 1px solid #ddd;
          height: 25px;
          line-height: 24px;
          float: left;
          text-align: center;
          text-decoration: none;
          color: #000;
          background:  url(tab-slide.png) no-repeat 2px -194px;
        }
        .tab-nav a.expanded {
          background-position: 2px -244px;
        }
    /* second level */
        .tab-nav ul ul { float: left; background-color: #333; width: auto; margin-left: 0;}
        .tab-nav li li {clear: none;}
        .tab-nav li li a { color: #fff; width: 100px; background-image: none;}
    The html:
    Code:
        <div id="tab-nav-2" class="tab-nav">
    
          <ul>
            <li>
              <a href="#">Person 1</a>
              <ul>
                <li><a href="#">Biography</a></li>
              </ul>
            </li>
            <li>
              <a href="#">Person 2</a>
              <ul>
                <li><a href="#">Biography</a></li>
              </ul>
            </li>
            <li>
              <a href="#">Person 3</a>
              <ul>
                <li><a href="#">Biography</a></li>
              </ul>
            </li>
     		<li>
              <a href="#">Person 4</a>
              <ul>
                <li><a href="#">Biography</a></li>
              </ul>
            </li>
             <li>
              <a href="#">Person 5</a>
              <ul>
                <li><a href="#">Biography</a></li>
              </ul>
            </li>
          </ul>
    
        </div>

  • #2
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Content show and hide in sequence

    Hello,

    I am trying to learn jquery. I did an example below to show and hide content in a group of div. the code works but i want to know if this is best practice to write what i did. Is there better way to do it?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Jquery selector examples</title>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
    <style type="text/css">
    .active {
    display: block;
    }
    .inactive {
    display: none;
    }
    #allwrapper {
    width: 400px;
    height:250px;
    background: #44ffaa;
    }
    
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
     $('button').click(function(){
    
       var contentDiv  =   $('div#allwrapper div');
       if(contentDiv !== undefined 
         && contentDiv.length != 0  
         && contentDiv.hasClass('active'))
       {
       var currentText =   $('div#allwrapper div.active');
    
       currentText.addClass('inactive').removeClass('active');
    
       //if(currentText.index() == (contentDiv.last().index()))
       if(currentText.is(":last-child"))
            contentDiv.first().addClass('active').removeClass('inactive');
       else     
    	currentText.next().addClass('active').removeClass('inactive');
       }
     }
    
    
    );
    });
    </script>
    </head>
    
    <body>
      <div id="allwrapper">
    
      <div id="content1" class="active">
        <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
      </div>
      <div id="content2" class="inactive">
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
      </div>
      <div id="content3" class="inactive">
        <p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
    
      </div>
      <div id="content4" class="inactive">
        <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
      </div>
    
      </div> 
      <button>Next</button>
    </body>
    
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •