Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slide content / page transition

I'm trying to recreate something like they've got over at gimmebar.com.

When you click an image, the content current page slides out left and fades out. The target page fades in and slides in from the right.

I've tried a couple of things, like creating two divs in a container with a width of 200% and scrolling the content in to view and using JqueryUI and slideing the divs. The scrolling failed with the divs not moving at all and srollLeft always being 0 no matter what. The slide worked somewhat better but to me it seems like they aren't run simultaneously. The second div just pops in to existence instead of nicely sliding in right behind the first.

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>slide demo</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <style>
    .container {
        width: 100%;
        float: left;
        height: 800px;
    }
    #one {
        background-color: red;
    }
    #two {
        background-color: #333;
        display: none;
    }
    </style>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>
<body>
    <div class="container" id="one"></div>
    <div class="container" id="two"></div>
<script>
$( document ).click(function() {
          $("#one").hide("slide", { direction: "left" }, 1000);
          $("#two").show("slide", { direction: "left" }, 1000);
});
</script>
</body>
</html>

It seems like it should be so easy to achieve but I'm stuck.

Take care.

Edit: I kind of got it to work as you can see in this fiddle. The slide is there but I can't see no fade. There also might be a better way of achieving this but I'm pretty satisfied with not having to load a third lib/plugin just to slide a div.

http://webadvent.org/2012/css-sliding-panels-by-bedrich-rios Found a tutorial written by their developer. Think that would count as the solution.

like image 229
Oskar Avatar asked Dec 01 '12 03:12

Oskar


1 Answers

A pure javascript solution: in the CSS:

div.wrap {visibility: hidden; position: absolute; overflow: hidden; 
    top: 0; left: 0; width: 100%; height: 100%}
div.wrap div.newContent {visibility: visible; position: relative; left: 100%;}

in the HTML:

<div class="initContent">
    This is the content that is initially displayed
</div>
<div class="wrap">
    <div class="newContent">
        Put the content you want to be revealed here
    </div>
</div>

The newContent div is initially hidden because its left edge is at the right edge of its parent (wrap) div, and the CSS tells the browser to hide any content that overflows the parent div.

Then to reveal the hidden content set a timer that progressively decreases the style.left for the inner div from 100% to 0% and increases the opacity from 0 to 1. I made a class for opening/closing swipey menus that could be adapted slightly to do this. (EDIT : a newer version)

like image 71
Stuart Avatar answered Sep 25 '22 02:09

Stuart