We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41970
    • 79 Posts
    I have a page with a slider, some content and a sub navgation. Now what I would like to achieve is, once the user clicks on one sub navigation item, the current content (slider and content, not the sub navigation) should slide out, and the new (clicked) content should slide in. My problem is that the slider and the content are in different div's, so how could I possibly achieve that effect, without full reload of the page?

    Here is the first one of the pages I am talking about. The other ones (Spa, Ownership etc.) will look similar to that one, and each page will have its own slider on top.

    http://prestigetrips.com/lapointe/index.php?id=9

    Any hints to point me into the right direction would be appreciated smiley
      • 3749
      • 24,544 Posts
      If you really want a slider effect, you'll need something like JQuery (though not Ajax unless you want to populate part of it with a php script in a separate file).

      If you just want replacement, by far the fastest way is to just use an OnClick() event to call a JS function that changes the class of the div, with CSS like this (untested):


      HTML:
      <button id="btn" onclick="swap()">Click me</button>
      
      <div id="div1" class="show">
         blah, blah, blah
      </div>
      
      <div id="div2" class="hide">
         blah, blah, blah
      </div>
      


      CSS:
      div.show {
          display: block;
      }
      
      div.hide {
          display: none;
      }



      JS:
      function swap() {
          document.getElementById("div1").className = "hide";
          document.getElementById("div2").className = "show";
      }
      


      Theoretically, you can skip the JS function altogether with this in the button HTML:
      <button onclick="document.getElementById("div1").className = "hide";document.getElementById("div2").className = "show";">Click Me</button>


      In JQuery, this should do a nice fade with the HTML and CSS at the top:

      $('#btn').click(function(e){    
          $('#div1').fadeOut('slow', function(){
              $('##div2').fadeIn('slow');
          });
      });
      


      You can also use slideUp() and/or slideDow() instead of fade().


      [ed. note: BobRay last edited this post 13 years, 2 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 41970
        • 79 Posts
        Thank you BobRay for your suggestions, I will try this out!
          • 32699 ☆ A M B ☆
          • 427 Posts
          Though it is a tad technical for a forum. I discussed this in my book in a chapter which shows how to implement Ajax with Modx Revolution getResources calls (and others).

          In essence you create a page using an empty template and with nothing in it except for a chunk which feeds a parentID to wayfinder. Use that to return your links to the div in question via AJAX.

          You could also run Wayfinder cached in chunks (or areas of the page) establish the default css display property of each div in question to be display:none

          And use a jQuery toggle to show and hide them.

          Basically if any of them are clicked Hide all of them, show only the one which was clicked.

          Also, think about looking at other carousels which may be more suitable for what you are doing.

            Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

            Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com