I am trying to get horizontal scroll using buttons.
I have a container that has several divs arranged horizontally, and I want to scroll through them using the specified buttons.
Please take a look at my attemp and tell me what I'm doing wrong.
HTML:
<div class="left">
left div
<button id="left-button">
swipe left
</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">
swipe right
</button>
right div
</div>
Jquery:
$('#right-button').click(function() {
event.preventDefault();
$('#content').animate({
marginLeft: "+=200px"
}, "slow");
});
$('#left-button').click(function() {
event.preventDefault();
$('#content').animate({
marginLeft: "-=200px"
}, "slow");
});
http://plnkr.co/edit/GxufhJaRJn2SfGb4ilIl?p=preview
I tried the solutions I found on the Internet. But my container continues to change, although I'm trying to fix it.
source
share