ImageGrid/ui/experiments/infinite-ribbon.html

141 lines
2.6 KiB
HTML
Raw Normal View History

<html>
<script src="jquery.js"></script>
<script>
function focus(elem){
$('.current.square').removeClass('current')
return $(elem).closest('.square').addClass('current')
}
function clickHandler(){
focus(this)
}
function shiftSquare(direction, n){
if(n == null){
n = 1
}
var cur = $('.current.square')
// trigger the event...
cur.closest('.container')
.trigger('shift'+direction, n)
// if we move to the same spot, do nothing...
if(n == 0){
return cur
}
// see if we need to rotate...
if(cur[direction+'All']('.square').length < n){
var sq = cur.closest('.container').children('.square')
var i = sq.index(cur)
// rotate...
return focus($(sq[ direction == 'next'
? (i + n) % sq.length
: sq.length - (Math.abs(i - n) % sq.length) ]))
}
// shift the current element...
return focus($(cur[direction+'All']('.square')[n-1]))
}
// shift focus left/right...
function next(n){
return shiftSquare('next', n)
}
function prev(n){
return shiftSquare('prev', n)
}
// these will roll the container...
// XXX this needs a means to update the element content...
function rollRight(n){
if(n == null){
n = 1
}
$($('.square').splice(0, n)).appendTo($('.container'))
}
function rollLeft(n){
if(n == null){
n = 1
}
var sq = $('.square')
var l = sq.length
$(sq.splice(l-n, l)).prependTo($('.container'))
}
$(function(){
$('.container')
.on('shiftnext', function(evt, n){rollRight(n)})
.on('shiftprev', function(evt, n){rollLeft(n)})
$('.square')
.click(clickHandler)
})
</script>
<style>
.container {
position: relative;
display: inline-block;
height: auto;
min-width: 0px;
overflow: visible;
white-space: nowrap;
font-size: 0;
background: gray;
padding: 10px;
}
.square {
position: relative;
display: inline-block;
vertical-align: middle;
text-align;left;
width: 100px;
height: 100px;
background: silver;
font-size: 12pt;
}
.current.square {
background: red;
}
</style>
<body>
<button onclick="prev(5)">&lt;&lt;</button>
<button onclick="prev()">&lt;</button>
<button onclick="next()">&gt;</button>
<button onclick="next(5)">&gt;&gt;</button>
<div class="meta-container">
<div class="container">
<!-- BUG: when current is first hell breaks lose... -->
<div class="square">1</div>
<div class="square">2</div>
<div class="square current">3</div>
<div class="square">4</div>
<div class="square">5</div>
<div class="square">6</div>
<div class="square">7</div>
</div>
</div>
</body>
<!-- vim:set ts=4 sw=4 : -->
</html>