![]() |
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Full-Time Underdog
Join Date: Jan 2006
Location: Hometown of the GOOD George W.
Posts: 26
|
For the latest redesign of my Agents Extraordinary site, I wanted to have one section of the page that would automatically slide back and forth horizontally, revealing different selections of links. (A bit like Panic Software's Coda page.) With some help from my genius brother, I finally got it working, at least in standards-compliant browsers. It was a bit of a pain, but it creates a cool effect, so I thought I'd share it with any interested parties.
First, the HTML. We're going to have three nested sets of divs -- a container that'll hold the whole thing and serve as its frame; a shifter that will slide back and forth within that frame; and the divs sitting inside that shifter, which will appear one at a time as the shifter slides back and forth: HTML Code:
<div id="container"> <div id="shifter"> <div class="pane"> Content goes in here! It suuuuuure does.<br /> <a href="#" class="shiftleft">Shift me!</a> </div> <div class="pane"> Content goes in here! It suuuuuure does.<br /> <a href="#" class="shiftright">Shift me back!</a> </div> </div> </div> Code:
#container { width: 400px; height: 400px; overflow: hidden; }
#shifter { position: relative; margin: 0; width: 800px; height: 400px; }
.pane { position: relative; margin: 0; width: 400px; height: 400px; float: left; overflow: auto; }
Code:
// Get the width of the outermost container div.
var getWidth = $('#container').width();
// When you click a link with the "shiftleft" class,
// slide the "shifter" div to the left by an amount
// equal to the width of one pane.
$('a.shiftleft').click(function(){
$('#shifter').animate({left: -getWidth}, 500);
return false;
});
// Slide the whole works back into its original position
// when you click the "shiftright" link.
$('a.shiftright').click(function(){
$('#shifter').animate({left: 0}, 500);
return false;
});
Code:
// Get the width of the outermost container div.
var getWidth = $('#container').width();
// Set a global variable to keep track of how far
// the "shifter" should be moved.
var setWidth = 0;
// Subtract the pane width from the amount by which
// the "shifter" has already been moved.
// Don't forget to give back the changed setWidth variable!
$('a.shiftleft').click(function(){
setWidth = setWidth - getWidth;
$('#shifter').animate({left: setWidth}, 500);
return false;
});
// Same thing in reverse.
$('a.shiftright').click(function(){
setWidth = setWidth + getWidth;
$('#shifter').animate({left: setWidth}, 500);
return false;
});
EDIT: Fixed code for proper multi-pane sliding. -- Nato Last edited by Nato : 08-28-2007 at 10:21 PM. Reason: Fixing bad code. |
|
|
|
| Thread Tools | |
| Display Modes | |
|
|