Reputation: 652
i'm working on a site which have links to the left and a content area on the right. I would like to get it to slide in and out using jquery like this site: http://www.templatemonster.com/demo/44960.html
This is my current code (could get jFiddle to work?)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style>
body {
/**background-image: url(../img/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
**/
background-color: red;
background-image: url(img/bg.jpg);
font-family:Arial, Helvetica, sans-serif;
height: 100%; margin: 0; width: 100%;
}
html,body { height:100%; }
#left {
position: relative;
margin: 0 5px 0 0;
overflow: hidden;
float: left;
width: 220px;
background-image: url(img/panel_bg.png);
background-repeat: repeat-y;
height: 100%;
}
#right {
position: relative;
float: left;
margin: 0 5px 0 0;
width: 630px;
height: 100%;
overflow: hidden;
}
div.panel {
position: absolute;
float: left;
height: 100%;
width: 620px;
margin-left: 10px;
background-image: url(img/content_bg.png);
background-repeat: repeat-y;
display: none;
}
</style>
<script type="text/Javascript">
jQuery(function($) {
$('a.panel').click(function() {
var $target = $($(this).attr('href')),
$other = $target.siblings('.active');
if (!$target.hasClass('active')) {
$other.each(function(index, self) {
var $this = $(this);
$this.removeClass('active').animate({
left: $this.width()
}, 500);
$($target).hide();
});
$target.addClass('active').show().css({
left: -($target.width())
}).animate({
left: 0
}, 500);
}
});
});
</script>
</head>
<body>
<div id="left">
<a href="#target1" class="panel">Target 1</a><br/>
<a href="#target2" class="panel">Target 2</a><br/>
<a href="#target3" class="panel">Target 3</a><br/>
</div>
<div id="right">
<div class="panel" id="target1">Target 1</div>
<div class="panel" id="target2">Target 2</div>
<div class="panel" id="target3">Target 3</div>
</div>
</body>
</html>
Any help would be much appreciated!
Upvotes: 0
Views: 1591
Reputation: 807
I have updated your code to get the content sliding in and out. I changed a few styles to make it look a little clearer in jsfiddle since I didn't have your background images.
I changed your jQuery variables to not use $ at the beginning (personal preference) but otherwise it is the same. I removed the "panel" class on your links and changed the way floating was set up on the left and right divs.
<a href="#target1">Target 1</a><br/>
Upvotes: 0
Reputation: 3656
I got it working pretty much as intended with some CSS changes. I just used position:fixed
on the menu, and position:absolute
on the sliding areas. I changed the background colors on the slides to ensure it's working. I didn't touch your jQuery. http://jsfiddle.net/T7LzN/2/
Upvotes: 1