HI WELCOME TO KANSIRIS

Jquery Horizontal Scroll on Click

Leave a Comment
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title></title>
<style>
/* Put your css in here */

.left{
float: left;
width: 10%;
height: 100px;
/*border: 1px solid black;*/
}

.internal{
width: 31.75%;
height: 100%;
border: 1px solid black;
display: inline-block;
}

.center{
float: left;
width: 78%;
height: 100px;
border: 1px solid black;
margin: 1px;
overflow: hidden;
/*will change this to hidden later to deny scolling to user*/
white-space: nowrap;
}

.right{
float: right;
width: 5%;
height: 100px;
/* border: 1px solid black;*/
}

 
</style>
</head>

<body>
<div class="left">
<button id="left-button">
<<
</button>
</div>
<div class="center" id="content">
<div class=internal>
div 1
</div>
<div class=internal>
div 2
</div>
<div class=internal>
div 3
</div>
<div class=internal>
div 4
</div>
<div class=internal>
div 5
</div>
<div class=internal>
div 6
</div>
<div class=internal>
div 7
</div>
<div class=internal>
div 8
</div>
</div>
<div class="right">
<button id="right-button">
>>
</button>
</div>
<script data-require="jquery" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script >
 
// Add your javascript here

$('#right-button').click(function() {
event.preventDefault();
$('#content').animate({
scrollLeft: "+=100px"
}, "slow");
});
$('#left-button').click(function() {
event.preventDefault();
$('#content').animate({
scrollLeft: "-=100px"
}, "slow");
});
 
</script>
</body>

</html>

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.