Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slide between pages using jQuery

Tags:

jquery

slide

I have a 4 page website and I want to transition between the 4 pages with a slide effect. I don't want to do this using an #ID. I want to press a button or the link to slide to the next page. I know this can be done using jQuery and I've seen websites that do this. Please help out. Thanks in advance for all suggestions, criticisms, and comments.

like image 322
Asif Syed Avatar asked Mar 01 '12 15:03

Asif Syed


People also ask

How to slide Html page using jQuery?

jQuery slideToggle() Method If the elements have been slid down, slideToggle() will slide them up. If the elements have been slid up, slideToggle() will slide them down. $(selector). slideToggle(speed,callback);

How does jQuery sliding work?

JQuery supports three sliding methods that are slideUp(), slideDown(), and slideToggle(). The slideUp() or slideDown() methods slide the elements in upward or downward directions respectively. Alternatively, the slideToggle() method determines whether the element is in the slideUp() state or in slideDown().

How do you toggle slideUp and slideDown in jQuery?

The slideToggle() method toggles between slideUp() and slideDown() for the selected elements. This method checks the selected elements for visibility. slideDown() is run if an element is hidden. slideUp() is run if an element is visible - This creates a toggle effect.

How do you slide down in HTML?

The slideDown() method slides-down (shows) the selected elements. Note: slideDown() works on elements hidden with jQuery methods and display:none in CSS (but not visibility:hidden). Tip: To slide-up (hide) elements, look at the slideUp() method.


2 Answers

Check out this tutorial and example http://www.queness.com/post/356/create-a-vertical-horizontal-and-diagonal-sliding-content-website-with-jquery

Basically, you have to set your CSS and HTML to have all the panels/screens you want as divs - rows and columns.

Then set a selector for each panel and bind a click event [Code from link].

$(document).ready(function() {

    //get all link with class panel
    $('a.panel').click(function () {

                //reset and highlight the clicked link
        $('a.panel').removeClass('selected');
        $(this).addClass('selected');

        //grab the current item, to be used in resize function
        current = $(this);

                //scroll it to the destination
        $('#wrapper').scrollTo($(this).attr('href'), 800);      

                //cancel the link default behavior
        return false;
    });


    //resize all the items according to the new browser size
    $(window).resize(function () {

        //call the resizePanel function
        resizePanel();
    });

});
like image 173
jose Avatar answered Oct 17 '22 15:10

jose


I suggest using jQuery to slide your content off the screen, after that is done use AJAX to refresh the content to your new page. Set the content to the other side of the screen and use jQuery again to slide it in from that side.

Something like this...

<div id='wrapper'> // this has a set width and overflow hidden
  <div id='content'>
    your content
  </div>
</div>

A user clicks on a link, animate the margin of 'content' so it goes off the page. Do your AJAX-ing, position the 'content' to the other side of the page (far enough so you can't see it), animate the margin so it will slide into view.

like image 35
Luke Avatar answered Oct 17 '22 15:10

Luke