Like this? Demo Made it a lot easier, readable and extensible. Sorry, I do not have access to jsfiddle in my current location.
HTML:
<div class="slot" id="slot1"> <div class="block">1</div> <div class="block">2</div> <div class="block">3</div> <div class="block">4</div> </div> <div class="slot" id="slot2"> <div class="block">5</div> <div class="block">6</div> <div class="block">7</div> <div class="block">8</div> </div> <div class="slot" id="slot3"> <div class="block">9</div> <div class="block">10</div> <div class="block">11</div> <div class="block">12</div> </div> <div class="clear"></div> <div class="slotActionWrapper"> <div class="slotActions"> <a href="#" id="nudge1Up">↑</a> <a href="#" id="nudge1Down">↓</a> </div> <div class="slotActions"> <a href="#" id="nudge2Up">↑</a> <a href="#" id="nudge2Down">↓</a> </div> <div class="slotActions"> <a href="#" id="nudge3Up">↑</a> <a href="#" id="nudge3Down">↓</a> </div> </div>
CSS
.block { height:58px; width:100px; color: #ccc; border: 1px solid #666; float:left; } .slot { height: 176px; width:100px; border: solid 1px black; position: relative; overflow: hidden; float:left; } .slotActionWrapper { width: 306px; } .slotActions { width: 102px; text-align:center; float: left; } .slotActions a, .slotActions a:visited { text-decoration: none; color: black; } .clear { clear:both; }
JavaScript:
$(document).ready(function() { $('#nudge1Up').on('click',function() { $('#slot1 .block').first().animate({marginTop: "-=60"}, 300, function() { var firstElement = $(this).detach(); firstElement.css('margin-top', '0'); $('#slot1').append(firstElement); }); }); $('#nudge2Up').on('click',function() { $('#slot2 .block').first().animate({marginTop: "-=60"}, 300, function() { var firstElement = $(this).detach(); firstElement.css('margin-top', '0'); $('#slot2').append(firstElement); }); }); $('#nudge3Up').on('click',function() { $('#slot3 .block').first().animate({marginTop: "-=60"}, 300, function() { var firstElement = $(this).detach(); firstElement.css('margin-top', '0'); $('#slot3').append(firstElement); }); }); $('#nudge1Down').on('click',function() { var lastElement = $('#slot1 .block:last-child').detach(); $('#slot1').prepend(lastElement); $('#slot1 .block:first-child').css('margin-top', '-60px'); $('#slot1 .block:first-child').animate({marginTop: "+=60"}, 300); }); $('#nudge2Down').on('click',function() { var lastElement = $('#slot2 .block:last-child').detach(); $('#slot2').prepend(lastElement); $('#slot2 .block:first-child').css('margin-top', '-60px'); $('#slot2 .block:first-child').animate({marginTop: "+=60"}, 300); }); $('#nudge3Down').on('click',function() { var lastElement = $('#slot3 .block:last-child').detach(); $('#slot3').prepend(lastElement); $('#slot3 .block:first-child').css('margin-top', '-60px'); $('#slot3 .block:first-child').animate({marginTop: "+=60"}, 300); }); });
source share