Dando início a nossa série de snippets.
$(document).ready(function() {
//evento onclick do a.next
$('.next').click(function(e) {
//movimento a div#foobar para a esquerda 1000px
//left: é a propriedade left do css
//1000 é o tempo em milisegundos = 1seg
$('#foobar').animate({left: '-=1000px'}, 200);
//e é o evento
//preventDefault == return false | evita que siga o link ou a ação.
e.preventDefault();
});
$('.previous').click(function(e) {
//movimento a div#foobar para a esquerda 1000px
$('#foobar').animate({left: '+=1000px'}, 200);
e.preventDefault();
});
})
<body>
<div id="foobar">
Coisas
</div>
<a href="" class="previous">Esquerda</a> - <a href="" class="next">Direita</a>
</body>
#foobar {
background: black;
border: 2px solid blue;
width: 600px;
height: 150px;
/* necessário */;
position: relative;
}
[...] This post was mentioned on Twitter by Ruan Carlos, jQuery Watcher. jQuery Watcher said: via @ruanltbg Click to animate position | Animações em click | jQuery | Ruan Carlos: http://bit.ly/9yePqx #blogpost [...]