Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created March 18, 2014 10:17
Show Gist options
  • Save iporsut/9617262 to your computer and use it in GitHub Desktop.
Save iporsut/9617262 to your computer and use it in GitHub Desktop.
jQuery Slide Example
<!DOCTYPE html>
<html>
<head>
<title>Slide</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.2.6.js"></script>
<style type="text/css">
#slide-wrapper {
width: 200px;
height: 200px;
position: relative;
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
}
#slide-frame {
height: 200px;
width: 600px;
margin: 0;
padding: 0;
position: absolute;
left: 0;
}
.staff {
width: 200px;
height: 200px;
margin: 0;
padding: 0;
float: left;
}
.red {
background-color:red;
}
.blue {
background-color:blue;
}
.clear {
clear: both;
}
</style>
</head>
<body>
<div id="slide-wrapper">
<div id="slide-frame">
<div class="staff red">
</div>
<div class="staff blue">
</div>
<div class="staff red">
</div>
<div class="clear"></div>
</div>
</div>
<button id="left">&lt;&lt;</button>
<button id="right"> &gt;&gt;</button>
<script type="text/javascript">
$("#left").bind("click", function() {
$("#slide-frame").animate({
left: "-=200",
}, 500, function() {
});
})
$("#right").bind("click", function() {
$("#slide-frame").animate({
left: "+=200",
}, 500, function() {
});
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment